SolidJSS
SolidJS3mo ago
37 replies
Dastrus

createEffect in loops

In my SolidJS project the user is able to create new widgets by calling a function and passing in a config object. Within that config object there is a property called 'sets' that's a record containing a name as key and some other properties. Let's say for my example it looks like this:

config object:
{
...,
sets: {
apples: {
query: {
page: 1,
limit: 20
}
}
},
...
}

Now in my application the config object is set into a store and I loop through the sets and create new objects with additional properties and a reference to the original store object for that specific set. Now this all works fine and dandy. However, whenever one of the set's "query" property changes I want to do something (i.e. set the url search parameters). So I thought I'd use createEffect in the loop, but that doesn't seem to work. I know I'd probably could create an effect that watches the whole "sets" property and go from there, but I thought that might watch more stuff than necessary and was hoping for a more refined solution. Does anyone know if I'm handling this all wrong and should be looking at a different solution? Here's my playground example: https://playground.solidjs.com/anonymous/792a83f5-54b5-4cc0-b1d5-14f2cddeb242
Quickly discover what the solid compiler will generate from your JSX template
Was this page helpful?