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:

  1. app component reflects history of updates of it's prop redirectpath. when comes null no redirect string adds history.
  2. there reducer returns plain string or null depending on action.
  3. by pressing button do redirect expect both actions (set_redirect , clear_redirect) provide changed state appcontainer component. latest 1 (clear_redirect) triggers render method null value.
  4. 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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -