score:1
Accepted answer
You can use map method to map thought the array and change the status to true.
useEffect(() => {
if (message) {
const newMessages = messages?.map((mess) => {
return {...mess, status: true}})
setCurrentMessage(newMessages);
}}, [message]);
score:1
Set the mapped state with useEffect
useEffect(() => {
const data = [...message];
if (data.length > 0) {
data.map((ele) => ({
value: "YOUR CHANGED VALUE",
status: ele.status,
}));
setCurrentMessage(data);
}
}, [message]);
Source: stackoverflow.com
Related Query
- How can I change the array key value before passing to the state in react?
- how can I change the value of an object in an array being mapped from state react
- React - How to use the current state value as a variable so i can set as a index inside an array
- How can I change the value of an object in an array in react redux when the action is called?
- How can I store previous values instead of storing the value in array of objects in react state
- How can i check if two state array shared the same value of not in React
- How can I change the state of one React component based on the value of its sibling?
- How can mock the value of a state and data in my react test
- How to update specific value when the state is an array of objects - React
- How can I update singular value of Array in React State
- How can I set the default state of a checkbox based on value in firestore in react table
- How to change the state of a specific value in an array with condition
- how do i update state in react for updating the value of an object inside an array using array.map function
- How can I change the state of subcomponents with React Router?
- How to change key value pair in React state in a handleChange function?
- How to change the value with all specific key in the nested state in ReactJS
- How to update a useState which has an array, inside this array I have objects this objects will update when the input value will change in react js
- How to update the value of a prop upon a state change in React
- React Native TextInput have a Default Value How can we update/pass DefualtValue as a Text entry when state change (onchangetext)
- How can i change a state in react when I change the size of website?
- How can i can change the value of a variable with if/else to return certain div in react
- How can I change the state of my sidebar in my React with Redux ASP.NET Core application?
- How to change the value of rowData state in react hook
- React: How I can change a state variable based on the value of another state variable?
- how can I set the reducer's return value to state object in component in react js
- How the value in checkbox tag can be pushed to the array of current component's state
- How can I change the state of clicked button only in react hooks
- How to instantly update react state after replacing the value from array
- How to update value of a key in object in an array with the new value in React useState in TypeScript
- Get the value by passing key to array of object in react and lodash
More Query from same tag
- Can not get radius value from Editable Circle onRadiusChanged event
- change background color of component on hover
- How to type a styled component without losing any prop with Typescript?
- react router and routes is not working , i could not able to navigate to blogs page
- Change hash suffix on build using react
- Best way to update MapBox layer based on API call?
- Rearranging react grid when screen resizes
- How to import the types of react-dropzone?
- How do I ensure axios call sets the state in useEffect?
- typescript - Is there a way to output the long date from datapicker
- React Testing Library - Context within onClick/onChange error
- Shoiwng menu while hovering on table row in reactjs
- How can I display GIF images efficiently in my Gatsby blog website?
- Best Practice for querying data from foreign table in Rails API for React
- Wave css effect with: after and: before
- Why does one function update UseState correctly but the other one doesn't?
- How to find a nested connected component using enzyme mount?
- React-Downshift - How to prevent clear by Escape key?
- Runtime error on custom PaperComponent of Material UI Autocomplete
- Unable to install npx create-react-app@3.3.0 nucampsite
- TypeError: Cannot read property 'filename' of undefined 'getting this error while creating a User'
- How to use redux-persist with custom middleware
- How to start typing text right to icon inside a input text?
- TalkJS error with User.id: [TalkJS] User: required field "id" is not given or not a string or a number
- In a Jest test where does the window object come from?
- React hooks: How to read & update state in hooks without infinite loops with react-hooks/exhaustive-deps rule
- the workflow bulit with webpack and react.when i run 'npm run dev',there is an error:Module parse failed
- How to update the value of useRef hook on window resize
- Gatsby with CDN reference
- Utilizing AND statement (two conditions) inside react ternary operator