Reputation: 23
This is how I have the code to save the changes
const handleChange = (e) => {
let { Nombre, value } = e.target;
setState({ ...state, [Nombre]: value });
};
And in the text field I have this: The problem here is when put the field "Value", when I give the value="Nombre"
it makes it impossible to write in the text field.
<Form.Group>
<Form.Label style={{textAlign:"left"}}>Nombre</Form.Label>
<Form.Control
type="text"
placeholder="Nombre"
name="Nombre"
value="Nombre"
onChange={handleChange}
/>
</Form.Group>
Upvotes: 1
Views: 62
Reputation: 203457
The issue is that you are not destructuring the correct event property to update state.
Destructure the name
and value
event properties. You'll also want to be in the habit of using functional state updates to update the state and avoid issues related to stale state enclosures.
Example:
const handleChange = (e) => {
const { name, value} = e.target;
setState(state => ({
...state,
[name]: value
}));
};
Upvotes: 1