How to make custom getter for store?
Can I do it like this?
I don't guess the getState function would be reactive. is it possible?
13 Replies
it is reactive, the error is about the types not being compatible
I just changed screenshot. The case is also possible?
you need to define the type for createStore as
Record<string, number[]>
or maybe key: keyof typeof state
So Solid detects which property is reactive even key is function parameter?
all properties of a store is reactive
But I'm not doing like 'state.colors[0]', I'm doing getState('color', 0)
basically as long as you access a property of the store, you're telling it to "subscribe if there's a tracking context like createEffect"
the same concept applies to props
doesn't matter
state.colors and state['colors'] are the same
Solid's reactivity isn't compile-time, it's runtime
Proxies makes this happen
I have nested properties. In this case, Can I make custom single getter?
why not
I have a question though, why the need for a getter when you can access it directly
Because it's my current situation. I have same properties as global or in pages.
Currently, I can't find best solution..
yeah I mean
instead of abstracting it
with
getState
why not access the state directly
is this just code preferenceBecause I'll have much more properties in global, page. Checking all "state.activeGlobalProps.includes()" always is so tedious. I have 70 props in each pages, also global one.
I think I'm missing something out but is there really a huge difference if you remove
getState
from your code
the way getState is implemented, you'll have difficulties having the correct type inference
like right now, you're experiencing type errors