In redux, when an action is dispatched, reducer will change the state accordingly, the component which have called the action, also have access to the state ( passed through props by Provider ). Am I right?
is the state the only way to access results of the action in the component? ( the component which have called the action ).
How about passing a callback function to the action, and using that to send the result back to the component?
When an action is triggered in the redux pattern, all the reducers run, but only the reducers which are to act on this type of action will do the reducing job on the store. Sometimes you can have an action that doesn't return an action type. I usually return an action object if I want a reducer to reduce a state in the application store, else I don't need to. Remember when a state is reduced, all the component rendering it's value are re-rendered.
I think you can design an action to return it results after its execution, but you will not be using the redux pattern fully.
I have never tried this before, but I think promises are a good option. I always use
axios
for fetching my results from the server, if the I have the result, then another axios is dispatch for the reducer to update the state, else a reducer for error handling is dispatched.Yes, you are right. When action is dispatched, you need to specify the action creator, inside action creator you can fire sync or async action (using thunk or saga) and each action create have actionType and payload(optional. On calling action inside action creator, all the reducers will get inform and matches the type passed by action.
As redux best practice, state should be changed by reducer(as a pure function), which passed as a props to component if you listening to that state.
you can pass callback function to action creator, action creator is just a function.