-
First of all, this is an amazing library and I'm just trying to understand how it works. The automatic dependencies tracking is a bit magic to me but I think I've got the basic idea. But after playing around, I see that the // create a signal and register an effect outside of a component:
const [count, setCount] = createSignal(0);
createEffect(() => {
console.log(count()); // won't trigger ???
});
setCount(6);
setCount(7);
setCount(8); I'd love to know why and how, thanks |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
This thread probably has the best explanation: The basic of it is while it isn't restricted to components, Solid's reactivity is built with frameworks in mind so it has automatic disposal and scheduling so it needs to run inside a Reactive Root. It isn't necessary to be components but it means that there is a wrapper. I hide that wrapper inside Solid's It is more than disposal though too since it is how we manage synchronous scheduling. Like wrapping your whole example in a |
Beta Was this translation helpful? Give feedback.
-
@ryansolid |
Beta Was this translation helpful? Give feedback.
-
@ryansolid Does it make sense to extract these primitives into a model-oriented npm package? Similar to how nanostores extracted a svelte compatible store library usable across component libraries & even in model-oriented libraries. Of course one could have solid as a dependency but solidjs seems like it's a ui-oriented package. I can see using solidjs as a dependency for model-oriented libraries, but using a ui library just for it's models (e.g. svelte) is a bit of a harder sell...presumably because some would not want to have multiple ui libraries as dependencies. |
Beta Was this translation helpful? Give feedback.
-
Man having state outside component is epic i used to use Zustand in React, even now i have solid-zustand but I'm just thinking is there any reason to use this instead of just having a separate file with my signals and use them where i need it? Amazing framework, using SolidStart to build my sass project. |
Beta Was this translation helpful? Give feedback.
This thread probably has the best explanation:
#242
The basic of it is while it isn't restricted to components, Solid's reactivity is built with frameworks in mind so it has automatic disposal and scheduling so it needs to run inside a Reactive Root. It isn't necessary to be components but it means that there is a wrapper. I hide that wrapper inside Solid's
render
function.It is more than disposal though too since it is how we manage synchronous scheduling. Like wrapping your whole example in a
createRoot
would only log 8 (since effects are scheduled to the end). If you just want to play around to get a feel for the reactivity without worrying about components, check out this codesandbox: …