cannot return null from connected component
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 432
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
- Issue Type: [BUG, FEATURE REQUEST, etc.]
over_reactVersion(s):3.1.7
I expected that since it is legal to return null from the render() method of a normal React component, that it would be legal to return null from the mapStateToProps function. I realize they have different return types, but it seems the meaning should be the same in each case (i.e., don't render anything).
However, it generates this error:
dart_sdk.js:15575 Uncaught TypeError: Cannot read property 'Symbol(dartx.keys)' of null
at js_backed_map.JsBackedMap.new.addAll (dart_sdk.js:15575)
at js_backed_map.JsBackedMap.new.addAll (js_backed_map.dart:95)
at Function.from (js_backed_map.dart:34)
at Object.jsBackingMapOrJsCopy (js_backed_map.dart:151)
...
The workaround is to render the unconnected version of the component, but pass it a special prop that means "return null immediately".
But the intent would be communicated more straightforwardly if the mapStateToProps function could return null on its own.
FYI: @greglittlefield-wf @aaronlademann-wf @kealjones-wk @evanweible-wf @maxwellpeterson-wf
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.
Research direction
Start by tracing the connected-component handling of mapStateToProps and reproduce the null return described in the issue. Check how the returned value reaches the map conversion that raises the TypeError. Done means a connected component can return null from mapStateToProps without throwing and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100