Pass state from Global and update in Children
Answered
Yellow Crazy Ant posted this in #help-forum
Yellow Crazy AntOP
How can i pass state from Global Layout, in this case, layout.js with RootLayout as functional component marked in red is the global layout where i have Navbar footer and mid section of children....
Now as user clicks on a link in navbar such as "login", it will display the login page mentioned from another screenshot in yellow where it says "loginPage"
As soon as user logs in, i am pushing dashboard link to router (is that the proper way to do it ? )
also as user logs in how can i change the userLoggedIn state from global layout by passing it as props and please can someone let me know how to send props in this structure, i'm stuck since 2 days now...
thankyou so much
Now as user clicks on a link in navbar such as "login", it will display the login page mentioned from another screenshot in yellow where it says "loginPage"
As soon as user logs in, i am pushing dashboard link to router (is that the proper way to do it ? )
also as user logs in how can i change the userLoggedIn state from global layout by passing it as props and please can someone let me know how to send props in this structure, i'm stuck since 2 days now...
thankyou so much
Answered by Yellow Crazy Ant
I tried with Zustand, but its giving me hydration errors..so i tried manually setting the localstorage using the Context there is slight delay when we manually change url, otherwise its good.. maybe i'll use zustand for future states...
thankyou so much
thankyou so much
7 Replies
you'll probably want to use Context here
it's common to store the login state/ current user in a context because most components will need it
Yellow Crazy AntOP
okay and if i have multiple state variables in the global layout, do i have to add everything in the context ?
btw i'm using Flask backend
and if i'm setting/adding state variables to context, can i access from any child and any parent ?
Yellow Crazy AntOP
Hello sir,
when using context, if i manually change the url, its resetting the state from from the context?
please let me know how can i solve that
when using context, if i manually change the url, its resetting the state from from the context?
please let me know how can i solve that
Yellow Crazy AntOP
I tried with Zustand, but its giving me hydration errors..so i tried manually setting the localstorage using the Context there is slight delay when we manually change url, otherwise its good.. maybe i'll use zustand for future states...
thankyou so much
thankyou so much
Answer