Notice: file_put_contents(): Write of 4927 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50

Warning: file_put_contents(): Only 12288 of 17215 bytes written, possibly out of free disk space in /var/www/tgoop/post.php on line 50
Frontender Libs - обзор библиотек JS / CSS@sWebDev P.3043
SWEBDEV Telegram 3043
Объединение объектов с useSetState в React

useSetState — это хук, который позволяет объединять объекты в их текущем состоянии, аналогично this.setState в классовом компоненте.

Пример использования:
import { useSetState } from 'react-use';

const Demo = () => {
const [state, setState] = useSetState({});

return (
<div>
<pre>{JSON.stringify(state, null, 2)}</pre>
<button onClick={() => setState({ hello: 'world' })}>hello</button>
<button onClick={() => setState({ foo: 'bar' })}>foo</button>
<button
onClick={() => {
setState((prevState) => ({
count: (prevState.count || 0) + 1,
}));
}}
>
count
</button>
</div>
);
};

В этом примере, кнопка "hello" обновляет состояние, добавляя hello: 'world'. Кнопка "foo" обновляет состояние, добавляя foo: 'bar'. Кнопка "count" увеличивает значение счетчика count на 1. Этот подход помогает управлять состояниями, объединяя их в один объект.

👉 @sWebDev
👍4👎1🤔1



tgoop.com/sWebDev/3043
Create:
Last Update:

Объединение объектов с useSetState в React

useSetState — это хук, который позволяет объединять объекты в их текущем состоянии, аналогично this.setState в классовом компоненте.

Пример использования:

import { useSetState } from 'react-use';

const Demo = () => {
const [state, setState] = useSetState({});

return (
<div>
<pre>{JSON.stringify(state, null, 2)}</pre>
<button onClick={() => setState({ hello: 'world' })}>hello</button>
<button onClick={() => setState({ foo: 'bar' })}>foo</button>
<button
onClick={() => {
setState((prevState) => ({
count: (prevState.count || 0) + 1,
}));
}}
>
count
</button>
</div>
);
};

В этом примере, кнопка "hello" обновляет состояние, добавляя hello: 'world'. Кнопка "foo" обновляет состояние, добавляя foo: 'bar'. Кнопка "count" увеличивает значение счетчика count на 1. Этот подход помогает управлять состояниями, объединяя их в один объект.

👉 @sWebDev

BY Frontender Libs - обзор библиотек JS / CSS




Share with your friend now:
tgoop.com/sWebDev/3043

View MORE
Open in Telegram


Telegram News

Date: |

The optimal dimension of the avatar on Telegram is 512px by 512px, and it’s recommended to use PNG format to deliver an unpixelated avatar. Telegram has announced a number of measures aiming to tackle the spread of disinformation through its platform in Brazil. These features are part of an agreement between the platform and the country's authorities ahead of the elections in October. Hui said the messages, which included urging the disruption of airport operations, were attempts to incite followers to make use of poisonous, corrosive or flammable substances to vandalize police vehicles, and also called on others to make weapons to harm police. bank east asia october 20 kowloon Click “Save” ;
from us


Telegram Frontender Libs - обзор библиотек JS / CSS
FROM American