I've noticed that some connected components will re-render even if their props have not changed. The steps to reproduce are:
{} or [];You can have a look to this codesandbox with react-devtools's Hightlight Updates option to see the third component being updated when clicking on the button.
Your Test3 example is creating a new array instance in its mapState function, thus causing the component to re-render every time:
const Test3 = connect(() => ({
test: []
}))(() => <p>Test3 does re-render when an action is dispatched.</p>);
Don't do that :)
It's the same thing if you call someArray.map() as well.
See the Redux FAQ entry on components re-rendering, and my post Practical Redux, Part 6: Connected Lists and Performance.
Most helpful comment
Your
Test3example is creating a new array instance in itsmapStatefunction, thus causing the component to re-render every time:Don't do that :)
It's the same thing if you call
someArray.map()as well.See the Redux FAQ entry on components re-rendering, and my post Practical Redux, Part 6: Connected Lists and Performance.