W
W
Wondermarin2020-08-04 11:26:53
React
Wondermarin, 2020-08-04 11:26:53

Tracking changes in state?

There are several states in the component code, each has an initial value received from the server. How can I track that one of them (or several at once) have changed their state from the initial one in order to prompt the user to save the changes or reset them?

Something similar can be found in Discord when changing profile/server settings.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Zolotarev, 2020-08-04
@ProGatti

As I understand it, you mean one state with different fields or several hooks. Check them with a conditional statement. For example, we have a text field. Here is the state under it: Hang on the text field onChange and setText (value) to it. Next, you can muddle a span under the text field, which will display the text if the field is not the right size (let's say less than 3 characters).
const [text, setText] = useState('');

{(text <= 3) && <span>введённый текст должен быть длиннее трёх знаков</span>}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question