You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which works well... however I want to init a component, and pass the state name into it somehow...
The problem: I have a store, which based on user interaction (from the dom) will create a new state object eg state.field_${id}, and then dynamically render a Preact component... I want to pass down the state name / ID into a preact component/wrapper so it can connect to its own state object - field_${id},
The only thing I can think of, is to just connect it to the whole state, pass in the ID, and then filter that out manually...
Using this method, I don't need to import unistore/preact and can designate specific props from a store's state to specific components...
Open to any suggestions of doing this another way but I think I'm quite happy with this implementation :)
rmorse
changed the title
How to "dynamically" connect to different states?
How to "dynamically" connect to different states with React/Preact?
Jun 11, 2021
I see that connect can be used like this:
connect( [ 'var1', 'var2' ], actions )
Which works well... however I want to init a component, and pass the state name into it somehow...
The problem: I have a store, which based on user interaction (from the dom) will create a new state object eg
state.field_${id}
, and then dynamically render a Preact component... I want to pass down the state name / ID into a preact component/wrapper so it canconnect
to its own state object -field_${id}
,The only thing I can think of, is to just connect it to the whole state, pass in the ID, and then filter that out manually...
But it doesn't sit right with me, and the component would naturally re-render on any state change rather the part we're after... .
Is this possible / are there any other approaches I might have missed?
Thanks!
The text was updated successfully, but these errors were encountered: