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:
const user = {
name: "john",
role: "admin",
active: true,
}
const user = {
name: "john",
role: "admin",
active: true,
}
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
Alex Lohr
Alex Lohr2w ago
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...
JonathanExcelsior
@Alex Lohr This is insightful!
Alex Lohr
Alex Lohr2w ago
Thanks.
peerreynders
peerreynders2w ago
My personal experience was
createSignal is great, createStore is better—wait a minute, often createSignal is exactly what I need.
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.
Alex Lohr
Alex Lohr7d ago
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.

Did you find this page helpful?