createSignal vs createStore
When should createSignal be used instead of createStore and vice versa?
If I want to store an object in state, for example:
Which is preferable, createSignal or createStore? Is there any performance benefits in using one over the other? Should createSignal only be used for primitive data types and createStore for complex data types? Should createStore only be used if you want nested reactivity?
I'm just trying to understand when best to use each.
5 Replies
I hope this provides an answer: https://dev.to/lexlohr/the-zen-of-state-in-solidjs-22lj
DEV Community
The zen of state in Solid.js
Cover image from https://www.pxfuel.com/en/free-photo-jsrnn Solid.js is a frontend framework that is...
@Alex Lohr This is insightful!
Thanks.
My personal experience was
i.e. assess your actual needs when it comes to the chosen granularity of reactivity. In some cases you may have compound data but there is no need for a store as the contents of successive values is highly variable anyway, so nested reactivity would be overkill.createSignal
is great,createStore
is better—wait a minute, oftencreateSignal
is exactly what I need.
That's what I said: try to split up state into multiple signals. Ofc, there may also be the case where a state object changes rarely but the expected changes are large enough to warrant a full re-render in any case. Do not waste time to optimize reactivity that is already sufficiently performant.