-
-
Notifications
You must be signed in to change notification settings - Fork 87
getDispatch should return all dispatch functions. #73
Comments
Unlike 1.0, you cannot do Was your error that you were trying to do |
Hey Charles, the error is that I'm not allowed to use hooks in a nested function. In a function component you're only allowed to access a hook from the toplevel of that function. (https://reactjs.org/docs/hooks-rules.html)
|
Basically what I need is a 'non-hook' way of retrieving a reducer |
Can you show the implementation of I am also in favor of a |
Sure, here's some simpliefied version of it:
Like I say, this is much dumbed down version of my code. In actuality I'm rendering a list of menu items based on some configuration where each item has an onClick method in which a reducer is used. The reducer is retrieved dynamically based on a key that is the same configuration. I hope I'm making sense ;) I see why hooks can only be called in the body of a component function, but as for retrieving reducers, I don't think that would mess with the component lifecycle. Hence a getDispatch method would certainly be useful. |
This feature is added and will deploy with 2.0.1 soon. Probably today. |
Thank you so much! And thanks for your work on reactn, I'm enjoying this library a lot! |
Hey there,
I'm in the process of porting my app from Reactn 1.0 to 2.0.
Now I run into trouble when I'm rendering, for example, a list of components in a separate (nested) function, where I want to use a reducer in the nested function.
I.e.:
I used to be able to just use getGlobal()[reducerName] to get a reference to one of my reducers, but in 2.0 I can only find the useDispatch hook to do this with. Unfortunately, I run into errors when using hooks in nested functions...
Is there another way of retrieving a reducer that I'm not aware of?
I appreciate your time and help in this.
cheers,
Roland
The text was updated successfully, but these errors were encountered: