Using `connect()` with `Immutable.Map` state object
See original GitHub issueMy store is an Immutable.Map
object, and I would like to pass it down my tree of React components. I suppose that in most cases I can get good performance by using something like PureRenderMixin
(or ES2015 equivalent) when doing so.
I started out simple decorating my App
class with @connect(state => state)
, and I got this error:
“Uncaught Error: Invariant Violation: mapStateToProps
must return an object. Instead received Map {…”
I’m able to do something like @connect(state => {return {state};})
, and then unwrap the object in App
’s render()
, but I get the sense that this is not an ideal solution.
Issue Analytics
- State:
- Created 8 years ago
- Comments:18 (8 by maintainers)
Top Results From Across the Web
Connect: Extracting Data with mapStateToProps - React Redux
The first argument to a mapStateToProps function is the entire Redux store state (the same value returned by a call to store.getState() )....
Read more >Using an ImmutableJS Object as the React Component State
When you call setState(), React merges the object you provide into the current state. So after setState you'll be left with an empty...
Read more >React, Redux, and Immutable.js: Ingredients for Efficient UI
Is it really necessary to use Immutable.js? According to official documentation reducer function in Redux should always emit a new state object using...
Read more >Using Immutable.JS with React and Redux - Fullstack.io
A guide on when to use Immutable.js and how to use it with Redux. ... If you use Map() or Set() from the...
Read more >Immutability in React and Redux: The Complete Guide
Update an item in an array with map; Update an object in an array; Remove an item from an array with filter. Easy...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Indeed, as @gnoff said above, you can’t just return Immutable object because we spread over the values you return, and this wouldn’t make sense with Immutable.
The idiomatic way is to do this:
only for the fields you actually care about, so
@connect
can bail out when the parts the component doesn’t need, did not change. I don’t suggest usingtoJS()
because AFAIK it’s deep, but deep conversions won’t be as performant as just extracting the stuffy you want.This is the way to go, and it’s more performant than just one
@connect
at the top.btw if you’re concerned about performance, make sure you check out reselect and Computing Derived Data.