Page content not updating on route change
I have the following page:
I navigate using this, which works for any other route, as it seems:
If any other information are needed, please @ me.
6 Replies
You are breaking reactivity:
Instead use
Thank you, that works! Could you perhaps explain why that is?
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Unlike Svelte, in Solid code is just code, i.e. code is not reactive. It is up to you the developer to compose a reactive graph from the reactive primitives that Solid offers. Solid's reactivity is a runtime feature, not some compiler magic (apart from JSX being wrapped in a render effect).
Within a component function there are two reactive elements:
- the props which are similar to the proxy that is returned from createStore
- the JSX which is wrapped in an implicit render effect.
The component function itself is just a setup function (React component functions are render functions) and once it has executed it is up to the reactive graph that you constructed to keep the UI up-to-date.
In the simplest case you could just reference the
props
inside the JSX (render effect); whenever a property on props
changes, that change will be reflected inside the JSX render effect; this is why destructuring props
breaks reactivity because destructuring simply copies the value (at the time of assignment) but it does not transfer reactivity to the assignment target.
useParams()
returns a reactive object.
would break reactivity
Is just a variation on the same theme. There is no destructuring here but it is just a simple assignment so reactivity is lost.
Neither of this applies inside an effect function or a memo function.
In that case the mere access to params
is enough to subscribe to change propagation - kind of. But in order to target the change you are actually interested in you should stick with params.id
in any case.Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
In the end you are managing:
- referential stability for things that you confirm that haven't changed.
- referential volatility for things on the level where you want change to be noticed.
A derived value will just work inside a memo/effect function
But that should highlight that the component function itself does not execute in an environment that similar to an effect or memo function because it's just a setup function (there is no re-render); just the JSX is reactive due to the render effect it is wrapped in and the
But that should highlight that the component function itself does not execute in an environment that similar to an effect or memo function because it's just a setup function (there is no re-render); just the JSX is reactive due to the render effect it is wrapped in and the
props
can be reactive provided they are used within a reactive environment.Thank you very much for the detailed explanation. This helps me better understanding this topic. Very well written and understandable!