Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!