S
SolidJS•4w ago
Valere

Hello,

I am using a store + createeffect to run a function when i set a specific value in the store. Is there a way to always trigger the effect even if the value didnt change ? I know its possible with a signal and {equals:false}, but for a value in a store ? Thanks 🙂
3 Replies
Madaxen86
Madaxen86•4w ago
Just as a thought: you could create a custom setter for this property which executes whatever code is inside createEffect. And you could get rid of createEffect entirely. Whenever you find yourself setting state inside an effect, ask yourself if you could redesign your flow. Most of "effects" could be a simple function call inside an event handler.
Valere
ValereOP•4w ago
Hello, Thanks for the answer. I'm not actually blocked on this issue, as there are many ways to solve it, like using a visibility property, etc. This is more for learning purposes , i was wondering if it's possible to force an effect to retrigger when using a store, similar to how it's possible with signals where you can configure them to ignore previous value equality checks. Since stores seem to be just collections of signals, I'm curious if the same functionality exists for store properties. edit: i think i didnt post this question on the right thread, ill ask the question elsewhere since im not really blocked so i wonder if it can fit "support". Thanks for your help!
bigmistqke
bigmistqke•3w ago
no, this is not possible with stores, they will always be equality checked. you can however compose it yourself:
const [listen, trigger] = createSignal<void>(undefined!, {equals: false})
const [store] = createStore({ get listen(){ return listen() }, trigger })
// Will be logged once and then again after 1 second
createEffect(() => console.log(store.listen))
setTimeout(() => store.trigger(), 1000)
const [listen, trigger] = createSignal<void>(undefined!, {equals: false})
const [store] = createStore({ get listen(){ return listen() }, trigger })
// Will be logged once and then again after 1 second
createEffect(() => console.log(store.listen))
setTimeout(() => store.trigger(), 1000)
playground
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template

Did you find this page helpful?