Yet another reactivity problem :cry:
Hi,
This is a small reproduction of a problem I have with reactivity.
https://playground.solidjs.com/anonymous/ea30129e-e6d3-45aa-9345-192095a33f1b
My main question is why the DOM is not updated whereas I return from the context a getter function (that should trigger the reactivity, right?) while the data is correctly logged in the console
I based myself on this example:
https://github.com/solidjs/solid-realworld/blob/f6e77ecd652bf32f0dc9238f291313fd1af7e98b/src/store/index.js#L17-L31
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
GitHub
solid-realworld/src/store/index.js at f6e77ecd652bf32f0dc9238f29131...
A Solid Implementation of the Realworld Example App - solidjs/solid-realworld
5 Replies
you're destructuring an object containing a getter, which is causing
reviews
to be evaluated once and then reusedhan
what would be the solution?
const reviews = () => usePost().reviews;
or is there something more elegant i'm unaware offyou are destructuring getters:
const { reviews } = usePost();
will do the trick
think of getters as function-callshhhmm damn i swear i read lot of articles on solid & reactivity still i make these stupid mistakes
thank you both for the clarification. i will definitely challenge every destructuring from now on!
ur welcome!
and yes totally get u dude, destructuring is also w me the trickiest thing to keep in mind when switching between solid and react back and forward.