function ProjectsComponent() {
const [state, setState] = useState({ one: 1, two: 2 });
const handleChange = (e) => {
setState({ ...state, two: state.one + 5 });
console.log(state);
};
return (
<form>
<input defaultValue={state.one} onChange={handleChange} />
<input defaultValue={state.two} />
</form>
);
}
When the first input changes, function handleChange
is triggered, which changes the state of key two
from 2 to 5+1 which is 6, but the second input default value defaultValue = {state.two}
is still 2, how to update its value?