In my code, upon submission of a form, I need to modify the state & then submit the updated state. Since useReducer is async, I can't access the updated state before form submission. How do I resolve this issue ?
const [data, dispatch] = useReducer(reducer,[]);
const cleanData = () => {
for(let entry of data){
if(!condition) dispatch({ type: actionTypes.delete, name: entry.key});
}
}
const onSubmitForm = e => {
e.preventDefault();
cleanData();
submitData();
}