I need to change state of specific fields in problems object:
const [problems, setProblems] = useState({
first_name: false,
last_name: false,
city: false,
email: false,
password: false,
});
I tried something like this below, but it updates for me just the last value of error Object.keys(error.response.data) list:
.catch((error) => {
Object.keys(error.response.data).map((err) => {
setProblems({ ...problems, [err]: true });
});
});
error is an object that has keys that have the same names as keys in problems object. How can I do this correctly that all fields will be updated?