X
X
Xenia2019-11-12 10:19:19
React
Xenia, 2019-11-12 10:19:19

Why does Redux only store one character?

Hello! I have a form:

<form onSubmit={register}> 

          <input
            name="name"
            component="input"
            type="text"
            placeholder="Имя и фамилия"
            onChange={setName}
          />
  
</form>

In action:
export function setName(name) {
    return {
      type: 'SET_NAME',
      payload: name,
    }
  }

It turns out to write only one character, which is stored in the store, but then you need to start over.
Please tell me how to fix this error?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Didenko, 2019-11-12
@xenia13

When you read this article carefully, you should understand everything Managed Components
Now you are doing the following: an action is hung on the onChange event, as soon as you enter 1 character into the input, the action fires and changes the state in Redux. Redux updates the state and re-renders your component, and you re-type a character and again update your state in redux with that one character.
UPD: no, Redux won't render for you, because you are not using the entered value in any way. In general, read the article and see the
sandbox example .
But try to understand, and not stupidly copy, this is very important

A
Ant Li, 2019-11-12
@ant13

5dca5eaeba59e343984271.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question