Telegram Group & Telegram Channel
Объединение объектов с 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



tg-me.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:
tg-me.com/sWebDev/3043

View MORE
Open in Telegram


Frontender Libs обзор библиотек JS CSS Telegram | DID YOU KNOW?

Date: |

A Telegram spokesman declined to comment on the bond issue or the amount of the debt the company has due. The spokesman said Telegram’s equipment and bandwidth costs are growing because it has consistently posted more than 40% year-to-year growth in users.

Telegram and Signal Havens for Right-Wing Extremists

Since the violent storming of Capitol Hill and subsequent ban of former U.S. President Donald Trump from Facebook and Twitter, the removal of Parler from Amazon’s servers, and the de-platforming of incendiary right-wing content, messaging services Telegram and Signal have seen a deluge of new users. In January alone, Telegram reported 90 million new accounts. Its founder, Pavel Durov, described this as “the largest digital migration in human history.” Signal reportedly doubled its user base to 40 million people and became the most downloaded app in 70 countries. The two services rely on encryption to protect the privacy of user communication, which has made them popular with protesters seeking to conceal their identities against repressive governments in places like Belarus, Hong Kong, and Iran. But the same encryption technology has also made them a favored communication tool for criminals and terrorist groups, including al Qaeda and the Islamic State.

Frontender Libs обзор библиотек JS CSS from us


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