Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
Reset input field in React (redux)

I am making a basic Todo application using redux, this is my first time using these methods of redux. I have a problem when I add the Todo the input field does not reset, I have tried various approaches and non seem to work.

For example: defaultValue, handleText on click to bring it back to an empty string, etc.

There are similar question on stack but non with my approach. Here is my code.

enter image description here

Reducer: enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In order to reset the value of the input field, you just need to set the state value of todos to an empty string, which you would do by calling:

setTodos('');

As you want to do that following the click, you can call setTodos following to the dispatch in the handleClick function:

const handleClick = () => {
  dispatch({ ... });
  setTodos('');
};

Additionally, you might want to initialize todos to a empty string instead of an array as it is used as a value for a text input:

const [todos, setTodos] = useState('');
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda