How to use Immutable.js as state?
See original GitHub issueSorry. Question again. I’m trying to use Immutable.js for the state. Here is my makeStore function
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import reducer from './reducer';
import Immutable from 'immutable';
export default function makeStore(initialState = Immutable.fromJS({})) {
return createStore(reducer, initialState, applyMiddleware(thunk));
}
and then I use this to 'wrap' the Page component
Page = withRedux(makeStore, (state) => ({
foo: state.get('foo'),
custom: 'custom value',
}), actions)(Page);
got error : state.get is not a function
can you suggest a way to make redux work with Immutable.js
thank you.
Issue Analytics
- State:
- Created 7 years ago
- Comments:21 (10 by maintainers)
Top Results From Across the Web
Immutable.js
Designed to inter-operate with your existing JavaScript, Immutable.js accepts plain JavaScript Arrays and Objects anywhere a method expects a Collection .
Read more >Understanding Immutable State with Immutable.js and ...
Immutable state means its value cannot be changed once it's created. That's it. You might be a bit concerned by this, after all,...
Read more >React, Redux, and Immutable.js: Ingredients for Efficient UI
In this Immutable.js tutorial, we will build a simple app using React and Redux ... Function shallowEqual will check the props/state diff only...
Read more >Using an ImmutableJS Object as the React Component State
I am trying to use ImmutableJS to help maintain state in a React component. I can use it just fine if the state...
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. ... an application-wide state that any component can access...
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
If you still want to use Immutable then you have to modify your
makeStore
function. In your sample ifinitialState
will be a plain object, it won’t be converted to Immutable. Function should detect if it’s an instance of immutable, and if not - convert it usingImmutable.fromJS
.I suggest not to use ImmutableJS, it’s useless, you can do everything with just spread operators
...
and immutable operations on objects and arrays. It only brings problems and forces you to smear all those.get()
methods everywhere in your code, so it will be hard to get rid of it later. Keep in mind, that per Redux’s contract, the store’s state is a plain object, so I can’t guarantee that nothing breaks with Immutable.Honestly I think it’s useless, especially for less experienced devs 😃 subtle performance benefits of write operations does not seem to be a good reason to sacrifice read performance or code readability…
I think that if someone is experiencing huge performance issues with ES immutable operations it just mean that the data processing is poorly architected, and ImmutableJS by itself will not help much. But that’s just my opinion.