lawftyg
lawftyg
SSolidJS
Created by lawftyg on 9/21/2024 in #support
issues with createContext and useContext
Hello, The other day I was working on a context with a store. I'll be the first to admit I am new at solidjs and was mostly following the guides for how to set up a context. The documentation i followed had a default value and setter function that was being added in the createContext function: https://www.solidjs.com/examples/context It's a function with an undefined return as in the example. I did this and then in the .Provider value={} passed a fully defined setter function akin to the one used there and the store accessor value. For some 2 hours I was ripping my hair out because no matter what I did updates were only effecting the page in which they were happening. And when navigating to a different page they would reset. Eventually I realised that defaultValue in createContext was overwriting the change whenever i would navigate out of a page, causing the values to revert to default and the setter function to become an undefined body. This doesn't seem to be the intended behavior? I removed the defaultValue from createContext and things started working with persistent changes. ... or so I thought, I retried today, starting up vite again. I now have an empty createContext() function but upon entering a page where I use the context I get an "(intermediate value)() is undefined" error that crashes the page. This error persists until I make a hotreload by saving a file I'm working on in the project. Suddenly everything is working again. It looks like I'm in a damned if you do, damned if you dont situation where the defaultValue will overwrite the context upon navigation, or the lack of a defaultValue will result in an error that makes it unusable. you can find my code here: https://gitlab.com/HappySmileySystems/kampdagenapp/-/tree/configs-flaten-to-array-of-stores?ref_type=heads there are two branches, the one I linked and error-default-value-in-context-store. both of these work. I appologize for the state of the code as I'm only proof of concepting atm.
3 replies
SSolidJS
Created by lawftyg on 9/15/2024 in #support
best way to update multiple children in a multi timer app?
Hey, I've been trying to Google this without much success. I'm trying to create a timer app that updates an array of components each tick. I'm wondering how best to go about doing this. I am thinking of having a parent component which somehow updates a child's internal time value but I don't know what would be the best method to do this. Can anyone give me any guidelines?
2 replies