I am new to React+Redux+Immutable js ,I am using toJS() to tranforming my Immutable Data structure to Native javascript form.But Recently I stumbleupon with this tweet
Author of Immutable.Js
Tweet says .toJS() is very expensive So can i go with toJSON() https://facebook.github.io/immutable-js/docs/#/List/toJSON is it ok with perf issue
UPDATE
const initialState = fromJS({
postArr:[]
});
const mapStateToProps = (state) => {
return{
posts:state.allPosts.toJS()
}
};
Pls provide some example with my own Reducer
How can i iterate this.props.posts
without using to.js()
From what I understand from the documentation:
toJSON()
returns a shallowly copied version of the immutable object (not a JSON string, although the name might suggest otherwise), which should only be used to pass to JSON.stringify()
(in other words: you shouldn't use it as a regular object in your code).
toJS()
returns a deeply copied version of the immutable object, which you can subsequently use/modify in your code. Because it's a deeply copied version, it's more expensive to generate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With