score:0
Coming back to my question a year and a half later with my own answer:
Always pass the immutable object if possible. If it's not immutable, just pass it as it is.
I decided that performance is much more important than how pretty the code is.
If a value is either immutable or mutable I pass it as it is and never call toJS
if I don't have to. I also won't wrap mutable values with fromJS
if they're not stored in the redux store.
I just need to be aware inside the child component that some props are immutable and some are not - and it's actually pretty simple because almost always a complex object will be immutable.
score:1
You should wrap your presentational components in a simple higher-order component that calls toJS()
on any Immutable.js object props passed to it.
This will give you the best balance of keeping the performance benefits of Immutable.js whilst keeping your container components from re-rendering too much, as well as keeping your presentational components dependency-free and therefore easily reusable and testable.
The Redux docs have a good selection of best practises for using Immutable.js, in particular, when not to use .toJS()
, why your presentational components should be kept pure and how a "toJS" higher-order component might be defined and used.
score:2
To pass props to component collect all data under a key as immutable.
<MyComponent propsKey={Immutable.fromJS({someData: {key: "value"}})} />
To use benefits of Immutable you should avoid from use toJS(). It is very costly and you cannot use useful Immutable functions with that. Until you reach "value", you should use Immutable.get(). It is annoying at first but, you can see how it is useful and easy to use, in time. (To get inner keys using getIn() can be less annoying than chain get functions). In this way your code can work more efficient and you do not need to use unwrap function, in your component you guarantee your data under this.props.propsKey always immutable.
Source: stackoverflow.com
Related Query
- When using redux with immutable-js - do you call toJS() on your selector? Or do you use .get('prop') in the render function?
- What happens when you use defaultProps when using redux with react?
- Getting an error "A non-serializable value was detected in the state" when using redux toolkit - but NOT with normal redux
- Prevent react component from rendering twice when using redux with componentWillMount
- What is the necessity of "export default connect" when you are connecting your react component to redux store
- How do you call fitBounds() when using leaflet-react?
- componentWillReceiveProps method doesn't run anymore when using redux to call api
- You should call navigate() in a React.useEffect(), not when your component is first rendered
- How to setup sublime 3 with react native so that when you click on the error and it jump to your code?
- Do you need action creators when working with Redux hooks?
- When Using Redux Saga with React Get This Error .. Uncaught TypeError: getPosts is not a function
- Infinite useEffect loop when using Redux with React Hooks
- How to minimize reducers boilerplate when using redux with a POJO state?
- Where should we do async Api call in Redux ,when you are using React-hooks?
- Failed with code 405 when using axios to make a call to controller api in asp.net core react application
- You should call navigate() in a React.useEffect(), not when your component is first rendered. (React+ReactROuterDom v6)
- React Redux Problem: How to call multiple api in your react component with React Redux Toolkit RTK queries?
- How do i prevent circular type reference in typescript with redux and connect when using mapState function?
- Using usestate hook with array when getting data from redux store
- Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware with redux tool
- UseEffect not fired when redux props change caused by async api call with redux-thunk
- How to access App components with Jest when using Redux container?
- When using useState with an array argument, how do you use useEffect to update a button dynamically?
- initialvalues is not shown in react-select when using with redux form
- How to call a function from different component using React with Redux Form?
- deal with IDs in components when using redux
- how do you call your data from redux into your app?
- React infinite loop when using useffect with redux
- How do you access query arguments in getSelectors() when using createEntityAdapter with RTK Query
- How to set a loading in component with Redux when call API
More Query from same tag
- My React list item components don't render one at a time
- Don't validate deletion in Material Table
- REACT: Can't set useState to an array of objects. Console log shows undefined
- How to hover over one chart to display a vertical line and tooltip on all charts in D3.js?
- How do rewrite this higher order function without using static functions?
- Toggle div visibility in react js
- ReactJs: Immutable Data
- React Native Expo StackNavigator overlaps Notification bar
- How to use useSwiper outside a Swiper instance?
- Cannot vertically align button inside UL
- How to save data in state which I'm getting from redux and then render directly instead of using .map() function?
- NextJS images - reload gif onClick
- React and text inputs - use onBlur or onChange?
- JavaScript React Redux: Field from Database is not Rendering in Web Page and Can't Select Value in DropDown
- Child component props not updating after parent's state changes
- I cannot use folder path in css in my react app
- Delay state change with async/await?
- Mobx react form confirm password issue
- React does not recognize the `totalPrice and totalQuantity` prop on a DOM element and Maximum update depth exceeded Error
- How to I consume nested data structures returned from Redux without running into errors such as 'cannot access property x of undefined'?
- React SVG import as a Component does not render
- Question about API fetch order using .then and useEffect
- How can I fetch arrays values in a list of items using GatsbyJS?
- React: How to return value from method of Context
- Unable to login with Google OAuth when deployed to Heroku
- One function to close a specified modal?
- React router is not working with webpack server and redux?
- react-chartjs-2 change axes text color
- implementation of react context doesn't work
- grunt browserify react requiring jquery