Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda