-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to "dynamically" connect
to different states with React/Preact?
#195
Comments
Ok so I might have answered my own question. I had a peek at the connect function and stole some ideas from there. What I've done:
So now I can do:
Using this method, I don't need to import 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"
How to "dynamically" Jun 11, 2021
connect
to different states?connect
to different states with React/Preact?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: