This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
Replies: 1 comment 2 replies
-
It seems |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How do you handle race conditions with state updating?
I have a bunch of state that I reset on a page load with a useEffect. A subcomponent depends on this state to trigger a certain set of actions, triggering action A if the state is set, and action B if the state isn't.
The problem I am having is there is a race condition from resetting the state and depending on the value of the state in a subcomponent that causes it to trigger the wrong action.
How do you handle reseting state and ensuring the right state gest used in useRecoilValue?
New Page Load
useEffect(()=>{ resetStateA(); },[])
Sub Component
const a = useRecoilValue(StateA);
useEffect(()=> {
if(a) { <-- The reset doesn't trigger in the useeffect and this fails
// Do action 1
} else {
// Do action 2
}
},[a])
Beta Was this translation helpful? Give feedback.
All reactions