What are the consequences of wrapping valtio in another layer? #81
Closed
MatulaDesign
started this conversation in
Show and tell
Replies: 2 comments 7 replies
-
It looks the store is just a set of proxies and I don't see any issues.
Glad to hear that. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hi @MatulaDesign // useStore
const useStore = (key) => {
const state = useProxy(state.get(key));
return [state[key], operators[key]]
} // component
const [auth, api] = useStore('authentication');
api.status()
api.set() @dai-shi is this approach appropriate with Valtio? When we use: useStore('state1')
useStore('state2') in the same component? Does it causes any impact on rendering? |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey!
First of all, imagine Janice from "Friends", with the iconic "Oh. My. Gaaawd". This is me when I discovered Valtio :D
Valtio is by far the single most convenient state tool out there. I tried all pmndrs' state solutions (and other libs I could find) to get the expected dev-ex, but Valtio is hands down the best for my style of coding.
Now, all butt-kissing aside, I wouldn't be myself if I hadn't tried making it even more enjoyable for me.
I wrote a small wrapper on top of valtio (because I like using strings to describe the targeted piece of state - sue me) and I was wondering if doing it like this might bite me in the butt somewhere down the line.
Simply put: how naive is this approach? (It works fine, the state updates etc etc)
Should I have used
subscribe
withsubscribeKey
? What I did kinda looks similar, but I am not quite sure how these two work, tbh.PS. TS is still a bit wonky here, but this is just a proof of concept that needs judgement
use
Beta Was this translation helpful? Give feedback.
All reactions