Most of us used to handle state using popular libraries like mobix, redux and so on.
SolidJS comes with great built-in capabilities for state management which we can utilize.
Hey everyone. I really wanted to start using solid and the first thing I wanted to understand and the cover was state management.
Let's create a UserService , it will be responsible for the user state.
As you can see we can use onMount on first render to preload our state from localStorage if it exists. We expose the state itself and updateUser in our return value. We can also expose methods for updating specific fields if we so wish.
Now I am going to create a context which will serve as access to all services the control specific states which cannot be mutated outside of those services
I have also defined a selector to retrieve the store context. Now we need to use the provider for our context
I can then access the store from anywhere on my application
This is the best I came up with on a moment's notice and wanted to share. Hope this is helpful for you :)