score:1
Accepted answer
try this:
setauthenticateduser({ ...authenticateduser, shoppingcart:[{...authenticateduser.shoppingcart[0],products:['newitem']}] })
score:0
const authenticatedusercopy = { ...authenticateduser }
authenticatedusercopy.shoppingcart[0].products = ['new product']
setauthenticateduser(authenticatedusercopy)
score:0
{
...authenticateduser,
shoppingcart: authenticateduser.shoppingcart.map(s => { //map all items
return {
...s,
products: [...s.products, 'new item'] //add item
}
})
}
Source: stackoverflow.com
Related Query
- Update value in nested object using React Hooks
- How to update the state of nested json object in react using hooks
- How to update 1 field only without overwriting others fields on a nested Object on React Hooks use Reducer?
- Using React Hooks useReducer, how can I update an object by ID efficiently?
- cant update context state when using hooks with a complex object to set providers value
- Update value in object in nested array in React Firestore
- REACT REDUX: Update value in deep nested object
- how do i update state in react for updating the value of an object inside an array using array.map function
- React update state object using hooks (useState) works, but no rerender
- update value of an object in an array - react hooks
- Toggle Value of One Item in an Object Using React Hooks
- Update object value in array React hooks way
- Update prevState of a value inside an array of objects of the respective item in React using Hooks
- How to update an Nested array using react hooks
- Change object nested property value using lodash in react
- change value of a nested object using setState hook in react
- React redux update nested Object property value
- how to update nested object using react and json-server
- How do I update states `onChange` in an array of object in React Hooks
- Using React Hooks To Update w/ Scroll
- React hooks: How do I update state on a nested object with useState()?
- UI not re-rendering on state update using React Hooks and form submission
- Update nested object using Object.assign
- Update React Hooks State During Render Using useMemo
- How to dynamically update the value for any input field with one event handler function, using hooks
- React + Formik: Use value for nested object
- How to update with React Hooks specific value of an array inside an object?
- Cannot update particular property of object in react js using setState
- Using React hooks, how can I update an object that is being passed to a child via props?
- React remove object from list of objects without unique value, using hooks
More Query from same tag
- Check if a condition is met before pushing a property into array ReactJS
- React: In react class component, should I use !== to match nextState with currentState
- React Jest how to test an external async await function being called?
- How to use Refs to change image src in React js
- How do i use one state with variables in, instead of multible states with a single variable in? (React)
- Hi I am trying to make a post request to my json server but getting unexpected results
- How to fix argument of type is is not assignable to parameter of type
- Render a React Form using a list of properties
- Unable to pass props to child component in react
- Dynamic width in React returns 'false' value
- undefined this inside next.js arrow function method
- Decrement and increment quantity with Reactjs
- next js react app undefined compilation error
- Open Modal in React JS Application on Page Load automatically
- Memory Router doesn't use the browsers back button
- how to remove href attribute from element in reactjs
- Using async await to retrieve images from firebase storage in react
- Conditional inside map() doesn't work as intended (React)
- How to get the value using react-rating component in my form?
- react django rendering same content
- With antd custom svg icons, how to pass props down to svg?
- TypeError: Cannot read property 'name' of undefined - Fetching data from restcountries API
- Updated setState Array from fetch request
- React Redux Private Route Best Practise
- Use JSON database with Node & React
- Debugging es6 in create-react-app
- How to connect my cli app to a website using websocket securely
- Two way binding of URL hash and Redux state
- Functions in React: my function isn't working, because of 'read-only' error. Why?
- Error in posting data through Axios to Django Rest Framework server,Error code 500