'How to update multiple dependent setStates in same function using Hooks in functional component
I have a Parent and Child Components. I pass a prop from the Child component into the a Parent Method that acts on multiple dispatches from a useReducer Hook using the following code
in Child
onPress={()=>props.clickTile(props.id)
while receiving the props.id inside the Parent method
in Parent
function clickTile(id)
this is needed to access dynamically created buttons and be able to reach their related state.
in Parent
if (tileOne !== null) {
setTileTwo(selectTile); //setState
//code..
if (tileTwo !== null) {// doesn't update until another click causing halt
//code...
}
}
however inside this method I have to call multiple conditionals as well as expressions using the same useReducer state causing issues due to the state not updating until the next click.
for more on passing from Child to Parent see my previous related question
PS. please suggest a better title.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
