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
Brendonovich
Brendonovich6mo ago
you're destructuring an object containing a getter, which is causing reviews to be evaluated once and then reused
No description
binajmen
binajmenOP6mo ago
han what would be the solution? const reviews = () => usePost().reviews; or is there something more elegant i'm unaware off
bigmistqke
bigmistqke6mo ago
you are destructuring getters: const { reviews } = usePost();
const post = usePost()

return (
<>
<pre>{JSON.stringify(post.reviews, null, 2)}</pre>
</>
);
const post = usePost()

return (
<>
<pre>{JSON.stringify(post.reviews, null, 2)}</pre>
</>
);
will do the trick think of getters as function-calls
binajmen
binajmenOP6mo ago
hhhmm 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!
bigmistqke
bigmistqke6mo ago
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.
Want results from more Discord servers?
Add your server