react-redux icon indicating copy to clipboard operation
react-redux copied to clipboard

useSelector(..) causing twice render - event the selected state doesn't change

Open namKolo opened this issue 6 years ago • 1 comments

What is the current behavior? Hello guys, I have some problems with the useSelector. It causes twice render of component. In a nut shell

 store = {
   en1: 'A',
   en2: 'B'
 }
 actions: { 
   changeEN1()
  }
  <ReactReduxProvider>
      | - EN1 (useSelector)
      | - EN2 (useSelector)
      | - EN1Connect (connect)

When I click a button in EN1, it will re-render EN1 twice, but EN1Connect only once. So I think we have the problem with useSelector. The Sandbox Link: https://codesandbox.io/s/awesome-zhukovsky-w82pb?file=/src/App.js .

After checking the source code, i think this is the reason. Please help me take a look: image

What is the expected behavior? It should render only once when the state changes.

Which versions of React, ReactDOM/React Native, Redux, and React Redux are you using? Which browser and OS are affected by this issue? Did this work in previous versions of React Redux?

namKolo avatar Jul 05 '20 13:07 namKolo

I found the reason .. Due to React.StrictMode problems. Thanks guys.

namKolo avatar Jul 05 '20 14:07 namKolo