Need clarity on eslint(solid/reactivity) warning use-case
I need help understanding how to deal with this ESLint warning when I am building a custom SolidJS hook library that doesn't have any visual components.
There is a portion of my custom hook code that gets called out by this warning and I don't know how I should properly resolve it (or if it is safe to ignore it).
The code snippet where I receive the warning is the following:
What is the proper way to address the warning in this case? Or is this something I can safely ignore perhaps?
3 Replies
I think the problem eslint is trying to point out is that if
database
changes, refreshRows
will use the new database but you'll still be subscribed to the old one.
Doing something like this may be better:
You could use database()
inside refreshRows
but eslint might still warn you that you're using a memo outside of a reactive context, at least this way refreshRows
will definitely use the same database value as the effectAh, extracting it out into a local variable and injecting it into
refreshRows
is a genius move and fixes the warning! Thank you so much for this insight and context! Super helpful! I feel like this use-case should be documented in the docs for that eslint(solid-reactivity)
rule.Do note that I used
createEffect
instead of onMount
too - otherwise the subscription won't be recreated when database
changes