Cuando uno desarrolla aplicaciones móviles con react es normal que al principio utilice repetidas veces las mutaciones de Estados para ver cambios reflejados en tiempo real pero uno desconoce que a la larga puede ser difícil de mantener y crea problemas de rendimiento.
When developing mobile applications with React, it's normal to use state mutations repeatedly at first to see changes reflected in real time, but you don't realize that in the long run, it can be difficult to maintain and create performance problems.
Un caso muy común de ver es cuando se trabaja con formularios ya que los formularios tienen varios campos que llenar y si recién estás iniciando en el mundo del desarrollo web es normal que pienses que cada campo debe tener una mutación de estado única pero esto crearía que tengas que estar aplicando cambios de estado por cada campo de formulario.
A very common case to see is when working with forms since the forms have several fields to fill out and if you are just starting in the world of web development it is normal for you to think that each field should have a unique state mutation but this would mean that you would have to be applying state changes for each form field.
Son un poco difícil de entender al principio pero manera resumida diría que es más fácil de administrar si se utiliza un solo estado que se administre a través de llaves y valores. Con un simple estado se pueden obtener todos los valores de cada campo del formulario y simplemente clonando los valores anterior se modifican los necesarios por el nombre de su llave.
They're a bit difficult to understand at first, but in short, I'd say they're easier to manage if you use a single state managed through keys and values. With a single state, you can obtain all the values for each field in the form, and simply clone the previous values to modify the necessary ones using their key names.
Tener un único estado para un formulario implica que es mucho más fácil de detectar dónde se puede llegar a encontrar el error en caso de existir y qué debe tener cada campo en específico.
En este código dejo una muestra tanto visual de la web como del editor de código de cómo a través de un único estado se obtienen todos los valores del formulario y luego solo necesito enviarlos a la base de datos.
Having a single state for a form makes it much easier to identify where an error might be found, if one exists, and what each specific field should have. In this code, I provide a visual example of both the website and the code editor, showing how a single state retrieves all the form values and then simply sends them to the database.