UI isn't updating properly depending on the context provider's state

hi, my UI isn't updating properly depending on the context provider's state
24 Replies
Tommypop
TommypopOP2y ago
this is how it's accessed in the child component
jesseb34r
jesseb34r2y ago
Are you using createContext?
Tommypop
TommypopOP2y ago
yeah I'll upload a pic of my context provider
Tommypop
TommypopOP2y ago
jesseb34r
jesseb34r2y ago
If so, to access the context you need to use the useContext syntax to access it
Tommypop
TommypopOP2y ago
I have
Tommypop
TommypopOP2y ago
and that's the function in my provider
jesseb34r
jesseb34r2y ago
Ah, I think the problem is that you need to pass in the useContext function so in this case the useUserContext function itself and then call that in the component. Passing the result of the useContext function breaks reactivity
Tommypop
TommypopOP2y ago
ooh
jesseb34r
jesseb34r2y ago
If I were on my computer I’d write up an example
Tommypop
TommypopOP2y ago
I'll try it thanks for the help
jesseb34r
jesseb34r2y ago
Np, if you can’t get it to work try to repro in the solid playground and I’ll see if I can edit it If the issue is solved if you would close the post that’d be great. Allows other posts to get visibility
Tommypop
TommypopOP2y ago
it's still being very weird logging it works fine but actually rendering it in the UI makes things break I'm starting to wonder if it is because of SSR as saving the file in VSCode which triggers hot reload makes it render properly
jesseb34r
jesseb34r2y ago
Try to repro in the solid playground
Tommypop
TommypopOP2y ago
yep ok
Tommypop
TommypopOP2y ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Tommypop
TommypopOP2y ago
It seems to work here which is really confusing me but it kinda supports the fact that it could be server-side rendering being annoying is there a way to disable it in solid start ?
Tommypop
TommypopOP2y ago
this warning also pops up
jesseb34r
jesseb34r2y ago
I am not as familiar with how to debug hydration issues. Maybe @foolswisdom or @thetarnav would be able to help
foolswisdom
foolswisdom2y ago
I can't be of much help - except that you should not use global state like that when writing code that isn't purely client side. Yoy don't want your auth state to be the same across all users the server handles, right? 🙂 Otherwise, I'm a little confused why you are putting the value returned from useContext into the provider? The whole point is that useContext provides the value most recently (in the tree) put in to the provider (or falling back to whatever was put in the context at the createContext call)
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Tommypop
TommypopOP2y ago
Hi, this works until I reload the page, where solid seems to lose track of the state because console logging the isAuthenticated variable returns the correct value but it displays the wrong button and if I make the button print the value in an onclick event, it prints the correct value which is mutually exclusive to it showing it is purely client side, at least after the initial server side render, which defaults the login state to false
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Tommypop
TommypopOP2y ago
Sorry, that's not what I meant, the state doesn't render properly when the page is loaded normally, where the state in isAuthenticated() is not equal to the state rendered in the DOM. However, when the page hot reloads, it presumably forces state updates, and the DOM becomes an accurate reflection of that value. Turns out the fix was to add artificial delay before updating the state on the client
Want results from more Discord servers?
Add your server