redux - Dispatching several actions in sequence for single reducer doesn't reflect changes in state for connected component -
when dispatching several different actions 1 reducer, last 1 triggers component update. might better show explain.
some notes on provided example:
app
component reflects history of updates of it's propredirectpath
. when comesnull
no redirect
string adds history.- there reducer returns plain
string
ornull
depending on action. - by pressing button
do redirect
expect both actions (set_redirect
,clear_redirect
) provide changed stateappcontainer
component. latest 1 (clear_redirect
) triggers render methodnull
value. - if add slight delay between dispatching these actions, both of them trigger component's render. can check pressing
do redirect delay
button.
i expect both changes (provided set_redirect
, clear_redirect
actions) in state should trigger component update without using settimeout
when dispatching actions.
i tried move dispatching of clear_redirect
middleware, after gets set_redirect
, same result.
can somehow reach expected behaviour?
initially posted issues redux repo, because thought it's issue in redux, @jimbolla explained me it's design of react.
here reference original issues , comments redux team member https://github.com/reactjs/redux/issues/2532.
don't ever rely on performing state updates in render()
. code should executed in render()
code required construct view.
you use componentwillreceiveprops
track when component receives new properties.
you should listen appropriate property , perform redirect when received. should listened property indicates redirection successful , can dispatch action clear redirect state if required trigger component update.
Comments
Post a Comment