You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constNavigator=()=>{constref=useRef<any>(null);const[authFlow,setAuthFlow]=useRecoilState(authFlowAtom);constinitialCheck=async()=>{// Here is the Promise that somehow affects rerendering)const[val,id]=awaitPromise.all([st.doesSessionExist(),getUserId()]);if(val&&id){setAuthFlow({loading: false,loggedIn: true,pop: true});}else{setAuthFlow({loading: false,loggedIn: false,pop: true});}};useEffect(()=>{initialCheck();},[]);useEffect(()=>{console.log(authFlow);// sometimes doesnt console log (should always console log when any function uses setAuthFlow)});consttrackLoggedIn=async()=>{constid=awaitgetUserId();constcurrentRoute=ref.current?.getCurrentRoute?.().name;constallowedLocations=['Login','Register'];constisCurrentModal=modalNames.includes(currentRoute);if(!id&&!allowedLocations.includes(currentRoute)){setAuthFlow({loading: false,loggedIn: false,pop: isCurrentModal});}};return(<NavigationContainerref={ref}onStateChange={trackLoggedIn}theme={navigationTheme}><TopNavauthFlow={authFlow}/></NavigationContainer>);};
This occurs in a Distant Child;
constsetAuthFlow=useSetRecoilState(authFlowAtom);type HandleLogin =({
email,
password,}: {
email: string;
password: string;})=>void;consthandleLogin: HandleLogin=asyncpayload=>{const{ data }=(awaitloginReq(payload,setError))||{};if(data){setUserId(data.id).then(()=>{console.log('called');// runs and sets every timesetAuthFlow({loading: false,loggedIn: true});});}};
I had to pass authFlow to the child to use, so that the parent subscribes. But the distant child that contains handleLogin gets setAuthFlow from recoilstate.
To fix the issue I've had to use local useState, and just make the Recoil State hold the setState function for the navigator. So really, the children are just calling setState on the parent, remotely.
The text was updated successfully, but these errors were encountered:
stephanoparaskeva
changed the title
Parent Not Updating on useRecoilState() sometimes
Parent Not Updating on useRecoilState() when using Promise.all([])
Jun 17, 2020
stephanoparaskeva
changed the title
Parent Not Updating on useRecoilState() when using Promise.all([])
Parent Not Updating on useRecoilState() on undetermined occassions
Jun 17, 2020
stephanoparaskeva
changed the title
Parent Not Updating on useRecoilState() on undetermined occassions
Parent Not Updating on useRecoilState() on undetermined occasions
Jun 17, 2020
So my Auth flow works just fine, But using recoil, the parent component doesn't rerender on all state updates from children via useSetRecoilState
Atom
Parent:
This occurs in a Distant Child;
I had to pass authFlow to the child to use, so that the parent subscribes. But the distant child that contains
handleLogin
getssetAuthFlow
from recoilstate.To fix the issue I've had to use local useState, and just make the Recoil State hold the setState function for the navigator. So really, the children are just calling setState on the parent, remotely.
The text was updated successfully, but these errors were encountered: