I'm making an app using React-Native.
I have a data array in redux state. I would say it's User's array.
I want to pick one user and get his data directly from reducer state.
But I can't get a return value from reducer action. And accessing a store and use getState() doesn't seem a good way. Firstly, it's too hard to access 'store' instance located in root component.
What options do I have?
I'm looking for something like calling an action and get the return value.
I want to pick one user and get his data directly from reducer state.
There is nothing like a reducer state. A reducer is a pure function that takes the previous state and an action, and returns the next state.
It should never be called by yourself but by redux to update the state. You can listen for state changes by connecting e.g. your react components to the store with the connect()
function from the react-redux package. If a part of the state that your components is listening to updates it will trigger a re-render of that connected component by passing the updated state as props. This is the way to react to state changes.
I'm looking for something like calling an action and get the return value.
Redux actions do not return anything. They just trigger changes of the global state which you can then listen to. If you need to e.g. fetch data (to update the state with) inside an action you need some kind of async action which e.g. redux-thunk provides.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With