S
SolidJS12mo ago
Mr Void

child-components not updating when parent state is modified.

Paragraph component: https://pastebin.com/raw/Y9tM6qgN Word component: https://pastebin.com/raw/zR6JCYbD Description The Paragraph component keeps track of Word components' data within a signal. It contains toggleWordMark function which is passed to each Word component as a callback function. Each Word, when clicked, calls toggleWordMark and its data is updated within the Paragraph's words signal. Problem The word components are not re-rendered when the Paragraph state is modified.
9 Replies
belst
belst12mo ago
looks like u want nested reactivity. you should probably use a store instead of a signal
thetarnav
thetarnav12mo ago
In toggleWordMark you’ve only shallowly destructuring the words array. Since you’re using a single signal, you should make sure to destructure all modified objects, in this case it would be the modified word. Nothing is updating because For is comparing references of items in each charge, and all references are in tact, nothing will update.
Mr Void
Mr Void12mo ago
Destructuring the objects have worked! Thank you <a:pepe_saber:1094297975141978214>
thetarnav
thetarnav12mo ago
Cool Now add a console.log("word created"); onCleanup(() => console.log("word destroyed")) to the Word component body and see if something isn’t right
Mr Void
Mr Void12mo ago
both print to the console 👀 Atm it doesn't completely work as expected Xd but there's a little progress I'm trying to get these Word components to highlight as normal text does when click+dragging the mouse over them I'm wondering; might it be a better idea to keep track of startIndex and endIndex within the store, then use createEffect for each Word that depends on indices and updates their own state when a change is made. thinkConfused
thetarnav
thetarnav12mo ago
Yeah the “selection state” could definitely be kept separate from the words list
belst
belst12mo ago
that's not right tho is it? you want to only toggle the class and not recreate the whole component. so it shouldn't destroy and recreate just to toggle a class
belst
belst12mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
thetarnav
thetarnav12mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template