react-redux 6.0.1: dispatch() is sending action to wrong store after store change

Created on 23 Jun 2019  路  1Comment  路  Source: reduxjs/react-redux

I know react-redux@6 may not be supported. Please feel free to close if it is not supported.

Description

Initially, we assign a store to <Provider store={ storeA }>. Then in the logic of a connected component, we call props.dispatch(), everything works fine.

Then we create a new store, namely storeB and switch to it thru <Provider store={ storeB }>. The subsequent props.dispatch() does not send actions to storeB but keep sending to storeA.

It does not repro on react-redux@^7.

Repro steps

You can find the live repro at https://codesandbox.io/embed/brave-leftpad-8bkfs.

  1. Create a new React project by npx create-react-app your-app
  2. npm install redux react-redux@6 --save
  3. Modified src/App.js as in CodeSandbox
  4. npm start
  5. Navigate to http://localhost:3000/
  6. Click "Increment", notice the value changed to 1
  7. Click "Use store B"
  8. Click "Increment" again

Actual

Notice after clicking "Increment" on step 8, the value did not change to 1.

If you click "Use store A", you will see the value changed to 2. It means the props.dispatch is being called on store A instead of B.

Expected

It should increment the value in store B to 1. The value in store A should still 1.

Versions

Most helpful comment

We're no longer supporting 6.0. You should use either 5.x or 7.x.

>All comments

We're no longer supporting 6.0. You should use either 5.x or 7.x.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

a-koka picture a-koka  路  3Comments

sajaddp picture sajaddp  路  3Comments

juangl picture juangl  路  3Comments

esayemm picture esayemm  路  3Comments

IbraheemAlSaady picture IbraheemAlSaady  路  3Comments