Stop infinite recursion when updating state
I need to update a store using it's previous value inside a createEffect.
I am using
import { useKeyDownEvent } from "@solid-primitives/keyboard";
to handle keyboard inputs.
i have a store
Now according to the docs , I am doing this https://primitives.solidjs.community/package/keyboard#usekeydownevent:
This is causing an infinite loop, since the value update of showChat is retriggering the createEffect.
Is there a way to read current value of UserSettingsStore.showChat in a non-reactive way, ie. prevent it from triggering infinite loopSolid Primitives
A library of high-quality primitives that extend SolidJS reactivity
4 Replies
use
untrack
untrack(() => !UserSettingsStore.showChat)
exactly I was looking for. i tried searching for it but I just wasn't getting it. Thank you so much
Instead of untrack u can also do
setUserSettingsStore("show chat", (showChat) => !showChat)
Thank you, I was using your type of implementation initially.
But I also had a few other use cases as well where I needed to access signals without tracking them. untrack helps in those places. Thank you for helping