score:1
Accepted answer
based on your quetion to merge the two state, you need to iterate over a state either 1 or 2, while merging them.
useeffects(() => {
const keys = object.keys(state1);
mergeddata = keys.map(key => {
// key will be 0,1,2 as with your quetion
return {
...state1[key],
...state2[key],
fullname: state1[key].name + state2[key].lastname
};
});
}, [state1, state2]);
Source: stackoverflow.com
Related Query
- React merge two states in third state
- How can i merge two state into single state in React Hooks?
- React Hooks useEffect saves the last state and won't update it with the new one. It runs twice with two different states
- How to make a shared state between two react components?
- Merge / Combine two or more different StyleSheet components in React Native?
- Deep merge of complex state in React
- synchronise scroll of two react components without using state and actions
- Is it possible to have two states in one react component
- React updating state in two input fields from form submission
- React useEffect hook with long running task and merge state
- react one state variable depends on multiple other states variables
- React - Combine data returned two api calls and set state of an array with these values
- How to pass objects and states between two components in React
- How do I merge two components in react
- react redux merge state with given array
- How to use multiple or two state values in one component or class file in react JS?
- Merge sort not working as expected react state array
- Changing state of third party React component from parent
- React useState Hooks - managing multiple loading states within a state
- Merge two arrays into one Array of objects React
- Transfer objects between two states in React
- why my react hook state only update after two clicks
- Accessing two states at the same time in react
- How to compare array objects present in two different React states
- not able to share state between two components in react
- Consolidate two state arrays in React
- How to create more states in react? Is the number of properties of react state fixed?
- How to pass two state variables into the same React useState? - Array & Integer
- How to best handle the state of one component used by two urls (1 sub url) in React / Router
- How do state updates merge in React hooks?
More Query from same tag
- Dynamic meta descriptions for certain pages in React SPA
- import error when using react-icons
- Redux props not showing in React component
- How to use react-router 4.0 to refresh current route? not reload the whole page
- React array did not update despite using useEffect
- applying middleware on store is not called reducer correctly in Redux
- Render on option in ReactJs
- Favicon in React will not Update
- How to load multiple documents in WebView from URL (PDFTron)
- How to apply classes on array of objects from another array based on id
- Time format of videojs
- Date and time (two fields) convert into UTC
- How do I convert a stream retrieved from S3 bucket to use it as jpeg image in my React frontend?
- ReactJS Form Submission
- How to change the style of a button when it is clicked in react using css?
- Type 'Element | undefined' is not assignable to type 'ReactElement<any, string | ((props: any)
- npx create-react-app is not creating servicework.js file in src forlder
- Can you fetch data in next.config
- How to share same function with multiple react components?
- React video element doesnt pause
- Implement Mobx ViewModel in React Component state
- useCallback doesn't call setState
- LocalStorage keeps changing my key-pair instead of pushing to the array
- passing parameter to a new page while redirecting in React js
- How to destructure redux state in react redux?
- React-Slick Carousel - Disable arrows
- React Router V4 - Page does not rerender on changed Route
- Is it possible to use redux and axios in react component library?
- Why is the MuiThemeProvider overriding a component style?
- onChange callback not firing in React component