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

136
Views
If there are many fields in form is it reasonable to create React.useState for each of it?

I have a form with 100 fields for example. I have two ways to deal with it:

  1. create useState hook for each of it
  2. create one
const [field, setField] = React.useState({
  a:"",
  b:"",
  c:"",
  ...
  ...
})

and deal with it like so:

setField(prev => ({
  ...prev, ...{b: 'Earth Worm Jim'}
}))

What is the best/right solution?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You could create a handleChangeInput func like this:

const handleChangeInput = (e) => {
    const { name, value } = e.target;
    setState((prevState) => ({ ...prevStatestate, [name]: value }));
};

Here it is important that the name attribute of your jsx, is the same as the state, so a, b or c...

about 4 years ago · Juan Pablo Isaza Report

0

You can mimic setState with useReducer hook like belows

const [state, setState] = useReducer((oldState, newState) => ({
    ...oldState, ...newState
}, {
    image: '',
    file: null,
    username: '',
    email: '',
});
about 4 years ago · Juan Pablo Isaza Report

0

I think there isn't problem when use useState() but if you want you can use useReduer() https://www.youtube.com/watch?v=kK_Wqx3RnHk

https://reactjs.org/docs/hooks-reference.html

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!