I am having an issue with setting an attribute from a state and dispatching it to the redux store. Here is my code:
const handleChange = (event) => {
setState(prevState => {
...state,
["name"]: event.target.value
})
);
dispatch(updateProfile(state))
}
updateProfile is a post request that should update the profile after a dropdown menu changes. However, when I try to dispatch, it says there is a null value, meaning that setState has not rendered yet and the initial value of state is still null. How can I make it so that setState renders, then dispatches correctly and there is no null value?