score:0
this type of question probably belongs at https://codereview.stackexchange.com/.
with that said. my suggestion. split it up into two reducers and combine them with combinereducer for a cleaner way. it makes more sence to have a single "updateable" (immutable) object as root.
my suggestion would then be:
companies: [{
name: "google"
}];
persons: {
"google": {
1: { name: "john" },
2: { name: "erica" }
}
};
if you need a key, or else feel free to use array as persons. i have always though maps makes better state objects and object.keys can be easily used to iterate through them later.
or you can ofcouse use your "method no 1" with a array of keys if that fits your backend and data structure better.
score:4
you should consider using a normalizing state shape for your store in redux.
using this approach i would suggest you to use your first approach where i suppose you keep separate various entities, like persons and companies, and linkt theme together using an id.
// first way
persons: {
1: {
name: "john",
},
2: {
name: "erica",
}
};
companies: [{
name: "google",
persons: [1, 2]
}];
Source: stackoverflow.com
Related Query
- Using pointers in Redux store
- I am using Redux. Should I manage controlled input state in the Redux store or use setState at the component level?
- Can I view/modify the Redux store using Chrome Dev Tools
- How to reset state of Redux Store when using configureStore from @reduxjs/toolkit?
- Access Redux store outside React when using next-redux-wrapper
- Using an API call in ComponentDidMount to update Redux store makes my component render twice
- How can I cache data that I already requested and access it from the store using React and Redux Toolkit
- React Redux Toolkit: How can I can store my initialState to localStorage using createSlice?
- how to delay checking redux store when authenticating using Higher Order Components
- How to retrieve data from Redux store using functional components and avoiding useSelector & useDispatch
- How to connect redux store using useSelector() when input fields already mapped using useState()
- Using Redux Toolkit, how do I access the store from a non-react file?
- How do you hydrate a store using react_on_rails' Redux API?
- How to reset Redux Store using Redux-Toolkit
- How to access Redux store using React Router?
- Next.js SSR store access token without using redux
- Using Redux Provider Store with Reactjs - error Store does not have a valid reducer
- How to get updated state from Redux store using redux-toolkit after component has already rendered?
- Edit Field not working & Managing form values using redux store - redux-form
- Replacing an object in an object array in Redux Store using Javascript/Lodash
- In a Functional Component, how do you access props from the redux store using react-redux connect?
- Set state of react component by using redux store
- How to get the data from Redux store using class components in React
- How do I stop state store data from accumulating in a redux component every time I navigate to it using react router
- How to create a Redux store using combineReducers without initial state
- How to reset the state of a Redux store using connected-react-router?
- How to connect a React component to my Redux store using a selector that takes an argument in Typescript?
- Using Redux default store from window in React app
- Using usestate hook with array when getting data from redux store
- Update part of object (nested) in redux store using immer and es6 in a normalized data
More Query from same tag
- React problem Cannot read properties of undefined (reading 'map') in a quiz app?
- React - ReactDOM.render to a div which gets loaded later
- Selenium (Python) + React
- React: How to route correctly on form submission?
- interface locationProps, Expected 0 type arguments, but got 1
- Preventing unnecessary rendering with React.js
- Restrict React route for the development only
- Axios returns index.html content to frontend (React.js)
- Problem reading state from React child Components using child->parent callback register model
- Why is react 'stl-viewer' not loading my stl file served by my private custom python flask api
- MUI 5 Autocomplete filtered options count
- How to create algolia autocomplete custom renderer using react class component
- basic JSPM React sample failing erroring on loading react-tools/vendor/fbtransform/visitors
- React.js Passing setState as prop causes a warning about using props for dependencies
- Value is coming undefined first, then is coming alright, but still receive undefined on the page render
- WebpackOptionsValidationError: Invalid configuration object. I cant deploy my server to try my bundle
- Using render in react router dom with a private route
- styled-components: Styling components without wrapping them in containers/wrappers?
- Attempted import error: 'Switch' is not exported from 'react-router'
- Pass a variable function to component in React.js
- React.js "Error: Too many re-renders. React limits the number of renders to prevent an infinite loop."
- Is it safe to share class instance in React Context API?
- onClick event handler not firing when updating state directly - ReactJS
- What's the right way to reset / initialize InfiniteLoader
- How to properly pass array interface/type to a child component in TypeScript React?
- Reactjs - createStore can't recognize the reducer when using typescript
- Objects are not valid as a React child (found: object with keys {seconds, nanoseconds})
- optimize image inside desired folder
- jest how set file pattern in package.json script
- Why are there extra required dependencies in package-lock.json?