`mapStateToProps` should not be called with functional component rendering a connected class component
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start with the linked CodeSandbox reproduction and compare the console output when toggling conditional rendering under functional and class parents. Determine whether the differing mapStateToProps calls are expected, then define the expected behavior before considering any change.
Written by the indexing model from the issue text.
Description
What version of React, ReactDOM/React Native, Redux, and React Redux are you using?
- React: 18.2.0
- ReactDOM: 18.2.0
- Redux: 4.2.1
- React Redux: 8.0.5
What is the current behavior?
Description:
- Depending on a parent component being a functionnal or class component, children connected component do not see their
mapStateToPropsfunction called in the same way
Reproduction:
- https://codesandbox.io/s/beautiful-gianmarco-wo67u0
- Click on toggle and check the console logging
- we can see a call to
mapStateToPropsin the class component child, when the parent component is a functional component ([APP1]) but not when the parent is a class component ([APP2])
Here is the logging, by app, when toggling off connected children (conditional rendering):
With a functional component as parent:
[APP1] CLASS CHILD MAP STATE TO PROPS
[APP1] NORMAL CHILD SELECTOR
x2 [APP1] NORMAL PARENT SELECTOR
[APP1] RENDER PARENT {showChild: false}
[APP1] NORMAL PARENT SELECTOR
[APP1] RENDER PARENT {showChild: false}
With a class component as parent:
[APP2] CLASS PARENT MAP STATE TO PROPS
x2 [APP2] RENDER PARENT {showChild: false}
[APP2] NORMAL CHILD SELECTOR
Note:
- FYI this led to an issue in our code when refactoring a component, with uncaught error in the
mapStateToPropsfunction of a child of that component, because suddenly it was being called with unexpectedstateand trying to get state on undefined keys.
Maybe all of this is a normal consequence of the inherent difference in React rendering functional or class component, but I still wanted to document this in an issue for the record, and see if you have any comment.
Thanks!
What is the expected behavior?
mapStateToPropsshould be called consistently (or should it not?)
Which browser and OS are affected by this issue?
Chrome OSX
Did this work in previous versions of React Redux?
- Yes
- Dominant language
- TypeScript
- Stars
- 23.4k
- Forks
- 3.3k
- Avg merge
- 10d 10h
- Merged PRs (30d)
- 12
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reduxjs/react-redux
-
Breaking Change
reduxjs/react-redux#2336 · 1 reaction · 1 assignee ·
-
Tests Tooling TypeScript
reduxjs/react-redux#2320 · 1 assignee ·
-
Dependencies Maintenance Tooling TypeScript
reduxjs/react-redux#2312 · 1 assignee ·
-
Dependencies Maintenance Tooling
reduxjs/react-redux#2309 · 1 assignee ·
-
Infinite Loop in `useEffect` When Dependency Chain Originates From unstable `useSelector` in v9.x Open
Difficulty 4/5 3-5 days Newbie friendliness 28/100
reduxjs/react-redux#2255 · 1 comment ·
All issues in reduxjs/react-redux
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·