showing results for - "update object in array state react"
Charlotte
13 Jun 2016
1let markers = [ ...this.state.markers ];
2markers[index] = {...markers[index], key: value};
3this.setState({ markers });
Nele
13 Jul 2019
1const initialState = [
2    { name: "foo", counter: 0 },
3    { name: "far", counter: 0 },
4    { name: "faz", counter: 0 }
5  ];
6
7const [state, setState] = useState(initialState);
8
9const clickButton = () => {
10	// 1. Make a shallow copy of the array
11	let temp_state = [...state];
12	
13	// 2. Make a shallow copy of the element you want to mutate
14	let temp_element = { ...temp_state[0] };
15	
16	// 3. Update the property you're interested in
17	temp_element.counter = temp_element.counter+1;
18	
19	// 4. Put it back into our array. N.B. we *are* mutating the array here, but that's why we made a copy first
20	temp_state[0] = temp_element;
21	
22	// 5. Set the state to our new copy
23	setState( temp_state );
24}
Stefano
19 Jan 2021
1const handleAdd = (todo) => {
2  const newTodos = [...todos];
3  newTodos.push(todo);
4  setTodos(newTodos);
5}
6
Brenden
03 Nov 2018
1this.setState(({items}) => ({
2    items: [
3        ...items.slice(0,1),
4        {
5            ...items[1],
6            name: 'newName',
7        },
8        ...items.slice(2)
9    ]
10}));
11
Emanuela
29 Mar 2019
1let newMarkers = markers.map(el => (
2      el.name==='name'? {...el, key: value}: el
3))
4this.setState({ markers });
queries leading to this page
array setstate reactreact state array replace elementhow to update array object with id in react jssetting array reactsetstate matrix index reactupdate an object in an array reactupdate data in array object with id in react statehow to add item existing list using setstate in reactupdate one item in state reactupdate state array with new array reactwhile update state of array objects reacthow to update state in arrayreact update array in statehow to use setstate to update value of arraysetstate update element in arrayreact update array of object by index in stateupdate array react state patchupdating array in state reactpush object into array reactupdating state with arrayupdate state array indexupdate state object in array reactset state change arrayupdate array of object where id using setstate reacthow to update a state with an array reactreact add item in each object in an arrayhow to update an array with use state react nativeupdate value at a array of index react update array element in react statereact replace whole array in statereact edit arrayreact add item to state arrayreact native set state with arrayreact edit object in array stateedit object in array react statereact render array state changeupdate state array directlyreact update state chnage one key in objects of array react setstate updating array of objects 3aupdate react array statesetstate specific array indexupdate any object in state arrayin state we having array of object then how can you change the object key in state in reacthow to change state array of objects property in reactupdate one value in array using setstate reactupdate array of object value in javascript reacthow to update reactonlyarray javascripthow to update arr in react jsreact update arrayreact js add object to arrayreact array add objectreact update array statesetstate react add to arrayupdateing array in state reactsetstate add to arrayindex of number in state arrayhow to update array of state using setstate in reactadd component react array stateupdate state array in react by object assignsetstate array update array objectschange data in array objects where value reacthow to set array in state in reactreact update one index of arrayhow to update an object in array in reactsetstate modify array itemhow to update an array inside an array of objects as state inreactfunctional component add object to a array value to stateupdate value of a react state array objecthow to update item in array state javascriptappend to state array reactupdate array state in reactchange state array of objects reactjsreact state changes for array statechange state of array of objectsreact state object array change valuereact how to change array state elementreact add element to state arrayreact push arrayhow to update an array of objects in react state usestateadd data into array in reacthow to set a specific index of a state array in reactinitialize array with value in state reacthow to update array value in setstate reactarray of objects react update valuesetstate update array itemsetstate in array reactupdate element in array state reactreact update item in state arrayhow to update a state array reactreact js update object in arrayreact checking matches in state arrayreact setstate object in arrayfind in array and change state reactupdate item in array state reactupdating an array with setstatte in react nativechange state array value reactjsreact add new object to state arrayreact state set array valueupdate an array state reactchange object in array reactupdating array state reactsetstate in arrayreact array in state update itemhow to change data inside an array in state reactreact replace array in stateupdate state array reeact hoolshow to update state of array in reactreact create copy of state and appendreact update state array of objects if changesetstate on one array elementhow to update state array in reacthow to add new object in array in react js update index of reactjs state arrayappend objects to state arraysetstate change array by indexreact update element in state arrayreact native update state array of objectsreact setstate update object in arraysetstate and retain your position in a listsetstate appendreact update an array in statepush array of objects into array reactreact native state update arrayreact change element in state arrayreact function change state arrayreact adding object to arrayhow to update array in react statehow to not replace array data using push in react nativereact state update object in arrayupdate item array in react statehow to update state of array of objects in reactsetstate array updatehow to update state of an object in arraypush value in state array reactreact set index of state arrayreact state array updatehow to change an item in objecy reactupdate array element in setstatehow to change object array value in reacthow create this state list arrayhow to update an array inside an object of state in reacthow to show updatged array afyer change in react jshow change array inside a state reactupdate an object in array in reactreact update an object in arrayreact setstate update array elementhow to update an object in an array in reactupdate setstate index arrayhow to insert array of object in state reactreact how to properly update arrays in stateupdate only on index array statehow to alter an element of a state variable array reactupdating single array element react native stateupdate array setstatehow to set state using an arrayupdate state of array inside objectreact js push array of objects into new arrayreact js setstate modify object in arrayreactjs update state array replacereact state modify object in arrayupdate array of array in setstateupdate array of object using setstate react with idupdate item in state array reactupdate my state with an array react nativeupdate state values by array index javascriptupdating an array in state reacthow to to assign array of statehow to define an array of objects as a state in reacthow to update array in reactreact update array of objects setstatereact update state object in arrayadd value in state arrayaupdate react state array to new arrayhow to update state with array reacthow to change update the state of slice in jsx reactupdate a value in array of objects reactupdate object inside array react stateupdate array in object react statehwo to update a state at an index javascriptreact setstate modify arrayreactjs setstate update arrayhow to update object in array reactupdate state of array react jsupdate array of objects in react stateupdate index of an array in state reactchange object inside array state reactupdate certain index in array in state reactreact state array of objects updatehow to update a array object value in reactreact setstate reference array itemreact setstate set indexsetstate array of objects by indexsetstate specific index arrayupdate specific index array react setstateadd poperty to object in array react statechange state in functional component react array of objectreact state array of objects handle changereactjs state update item in arrayupdate array setstate 28 update state in react array element at indexhow to update an object in a state array reactreactjs state array updateupdating array of objects react statereact update state array of objectsreact add array object element in stateupdate array using setstateupdate value array of objects reactreact state change elent in arrayupdate object array react statehow to decalre an object inside array in react statesetstate of object in array reactreact setstate update item in arrayhow to push element into array state reacthow to update obj of array in reactset array of object in react statereact modify array in statemodify object in array with react setstatereact native how to update an array in statereact change array item in statehow to edit array in react stateupdate state when array update reactsetstate to update arrayupdate value in react jschange object in array state react jshow to update an array of object in reactreact update array of objects in use 7estatehow to update array element in react stateupdate value at an array of index reactupdate array of objects with setstatehow to setstate elements inside an array in reacthow to update value in array of objects javascript use statereaact set state update arrayupdate value of variable in array by setstatereact js update array valuefind and replace object inside array on state reactreact replace item in arrayreact native state array serach valueupdate state array with dictionary reactreact updateing a state with an arrayreact update array valueupdate an array of object stateset array in state reactposting react state arrayreactjs set value of specific array element in statesetstate map array d 27objet by indexaddding value to state set reactchange value of object in state react arrayhow to add an object to an array in react state and map it in a listreact add to array statehow to update each value in state array in react jshow to change state of array of objects reactreact change object value in arrayappending to state array in reactadd object in array react jshow to update array state in reatreactjs update object in arrayupdate a component state arraryhow to update array of object in reactreact update array index in statehow to store state value in array in react jshow to add new value in an object array property in reactupdate an array which is inside an array of object on reactupdate an array with statereact change state in arrayreact setstate update array of objectsstate update list reacthow to update an array in react jshow to update an array in react statereact state array of componentshow to edit array item in react statehow to display state arrayupdate state on object inside array reacthow to update array of object specific index in reactreact js update state array of objectupdate array in a state objecthow to update an array of objects inside an array of objects reactreact native update state object in array react add something to the end of an array in statereact state update value in arraychange state of array in reactupdating an array with setstate in reactreact setstate update value in arrayhow to change state after filter and again set it to original value in reactupdating arrays in reactmutate array element in reactupdate list value in react usestatereact update state in for arrayreact state array object updatebest way to mutate an element in an array of stateedit state using mapreact update state array of objects functional componenthow to to put number inside array in statehow to update one data in an array state reacthow to update array of objects in reacthow to update state array change setstate 28 28state 5b0 5d reactupdate object value in array reacthow to update only one element from array with object reactjsreact class component state array modifystate from array in javascriptbest way to update array of objects in statemodify state array react declare array in stateupdate data in array in react statereact set push arrayupdate array set state with updated elementupdate an array statesetstate push to arrayreact setstate of array itemchange value in array state reactjs react add to array stateupdate array element in state reactreact change value in state arrayuse previous state array reactupdate state of array inside an object react usestateupdate object in arrayreactreact update object in arraycomponent state won 27t update arrayreact change state arrayreact add on arrayhow to update array in react jsedoting an object in an array in react stratereact add item to array in state functional componentjavascript update state arrayget idx from setstate in reacthow to update single object from array of object state in reactupdate state array of objects reacthow to change the index position of an item in a state array and the do setstate in react nativereact state with arrays labelshow to handle state array reacthow to add to state array reactsetstate for array how to update an array of objects in react statehow to modify element in array statehow to add new object to array of objects state reactmodify object in array reactreact state edit arrayupdate the object values in array of objects reactreact array state updatestate to contain arraysfix object in array state reactreact native setstate on one array elementyhow to update the array object in setstatereact how to update array in stateuse state update array of objectsreact state update arrayupdate react state of array of objectupdate field value in react state array of objectsupdate array in react jsupdate state data from array of objects reactjs this setstatereact setstate update property of object in arrayadd object in array react how to update state array in jshow to set objects of state of arrayreact push into array of objectshow to update an specific object in array and setting state in reactreact state array change itemupdate object inside array reacthow to add array data in state reactset state array in reactsetstate append to arrayupdate array value in react react change array statehow to update specific index in react array statereact state array add itemreact native update state array element key valuereact update array of objects in stateupdate one element of array of objects reacthow to add an object to current state arraystate in react doesn update array elementhow to update array in object statearray in react classarray set 28index 29 reactfind and update state reacthow to chnage value of array in state reactappend objects to state array reacthow to update the state array in react when update its elementupdate array of objects state reactreact setstate array object assignhow to update state array reactupdate array of object array in reacthow to update react statereact native change value in arraystate with array of objects 2c change one object react stateupdate an object o farray in set statereact class update value in arrayadd object to array reactreact updating array statereact making changes to an arrayupdate object in array state by indexupdate an array of objects react statechange state arrayreact state replace arrayarray object add in stateupdate state in react array elemenbtreact modify state array of objectschange array state reactupdate state of array reacthow to access array and update array in object in react nativein mongoosehow to update a state of element in array in reactsupdate array value in react jsupdate data in state array react nativeupdate react state array in objecthow to change state array value in reactsetstate arrayshow to update array in state reactreact native setstate update arrayreact state update of copy arrayupdate array react stateset objects inside array state reacthow to push item inn state array reactreact class component access state arrayreact update state on array key valuehow to update array of objects in react at pertucular indexhow to set state for an array in react jsreact native update array of numbershow to add object to array in react jshow to update one prop of an array in react statereact update value of state arrayupdating arrays with reactset state for item in arraytraverse array and set state of particular index reactreact update state array at indexreact add array to statechange object property in array state reactupdate state array reacthow to identify and update an object in an array in state 3a react usestateupdate array with new object react statereact updating state in arrayedit item in array state reactupdate array by index state reactreact how to update state arrayupdate value of array in s state reactreact update element of arrayhow to update array state elements reactconcat state in class componentreact native setstate arrayreact find replace in state arrayupdate new object array reactupdate state array object react esupdate value in state array react class componetnchange element in array react statestate change value in array objectmodify one index of array stateupdate a state array value reactsetstate array object reactupdate react state array objectreact update state onereact native update array in statebased on index update array of obh 3dject valuereact add to array of objectreplace array of object in state reactreact array concat popupdate react state of an arrayreact array updatereact state change object within arrayreact update state arrayreact update an array state by new arrayhow to change one element of state array reactupdating array in reacthow to update object of array in reactupdate array state with an objectarray state change reacthow to change state of an array in reacthow to update array data in react jsjsx on change object in array dont updatereact state change array item 23react native setstate object arrayreact ustate update in arrayarray of object change status react statereact set value arrayset state for particular index of arrayupdating a state array reactmodify array of object in react stateupdate value on object inside array reactreact update state array elementupdate only one index state arrayhow to update array state in reacthow to add an object to current state array reactreact set value after update in the arraywhy put arrays in statereact get objects and append in arrayhow to update object in array usingusestatehow to change array state in reactupdate an array data using set statereact update item in array statereact add object inot araray objecthow to update an array element in reactreact typescript setstate arrayupdating state of an array in reactadd data into an array in a state objecchange value in array state var in reactchange one element in state arrayreact setstate append to arrayreact js add array to statehow to add an object to a state arrayhow to update state array in react nativechange state by adding to array jshow to add new element to array in array in react statehow to update array object value in reactedit object inside array from the state reactupdate array from in react jsreact do i use setstate to change object in arrayupdate react state array item valuehow to update part of a state that is an array of objects in reactreact state replace item in arrayreact change only second element of arrayupdate state 2breact 2barray of objectreact add new element to array in statereact change array item in state setstateupdate array of object in statereactjs push object to array state arrayreact updated array object assign to original arrayupdate one object in array state reactchange array in statereact state change array itemreactjs update item in arrayset array state setstateindex based update in react updating all array elementsget object data and push to new array react jsupdating state array in reactupdate array in state reactadd data to existing array of objects in reactupdate one value of a state arrayset an obj in state arrayreact replace object in arrayhow to update array in setstateupdating state when state is an array of objects react how to update the array in new statehow to update a particular object in array in react statereact setstate update array of objects 3areact append object to arrayhow to update an array that is state in jshow to update data of state array of objectshow to change a object element of an array in setstateupdate object insed array insed state react classhow to update array in react jsupdate array with index set statereactjs update state array itemupdate my state with an array react naitveupdate array in reactreact state array change valuechanging array in state reactreact add to array of objectsupadte state of an array in react react update state with array of objects functional componentupdate state in one element in array of objects react functional componentobject add array react jsreact update state of an arrayhow to update array of state using setstate inside componentwillmount in reactreact how to set state when state is an arrayreact state array object update propertyreact update state object arrayset state for specific index in map react jsreact modify state arrayupdate state array of objects react with indexreact change state array at indexhow to push value in state array reactchange item in array state reactreact update array object in statereact update state array itemmaintaining an array in state in reacthow to upadte array element in react statehow to update state array of objectsreact state update one element in arrayset a value inside array of objects reactjavascript react update array statereact ahow to add object in array react componentreact edit array in stateupdate an array in react stateadd poperty to array of objects react statehow to update state in react arrayupdate value of array in s state react at particular indexreact push to state arraythi setsstate add item to arrayreact state update array object element propertyhow to update array statesetting array in state reactadd value to state array reactarray update reactupdate array react stathow to update array object value in react jsreact setstate array of objectshow to push in list and set sstateupdate object array state reacthow to update state in array jshow to update an array in an object reacthow to update the component when i update an state arrayreact 3a get an array object to update on propoerty state changeupdate react state arrayreact array object updatechanging arrays in state reactupdate object in state array reactsetstate update array indexadding to state array reactreact array update itemreactjs update statehow to update a element in array statejs save state data to arrayhow to make a state array with key pair elements in react nativehow to update array of objects in react statearray in object state changereact native state set object to array stateupdate value in an array react setstateupdate state with object arrayupdate array in array state reactset existing index value tp 0 reacthow to add to state array react jsadd array value in react state in class componentstate array change element with indexupdate value of array stateusestate update array of objects from props datause state update arraypush array setstateupdating react state arrayupdate array object element reactreact update whole state array of objectsreact update array at position indexappend data to state arrayhow to change state of array in reactreact state change for arrayhow to change object value in array state reacthow to update array state in react nativereact update array datachange the state ofa array of object using idupdate array state in reactjschange state of element of arraysetstate to an arrayhow can we push the values in to array as array of objects in reacthow to change an array of statereact state array update itemhow to push array elements in side astate array in reacthow to add data in state array in class componentset state array object react js doccumentationupdate an array state in reactusestate update array of objectshow to change array state reacthow to change array element of state in reactadd to state arrayupdate array of objects reacthow to update a value in array of objects stateupdating array state in reactreact set arrayupdate react state array with indexreact setting state in an array of arraychange array in state reacthow to access array state attributeadd item from array reactreact update state from arrayreact native state array update elementset state react update arrayreact set single array itemhow to store values in array in react jshow to change state of array in react with indexupdate object in array in state reactsetstate update arrayhandling array in setstateupdate object in array javascript reactupdate array element reeact wayupdating objects and arrays in react statereact set arrareact update array in state and set keyupdating single array item in state variablechange a value inside an array in a state in react with setstateupdate element in array by index reactchange value of object inside an array using javascript react statehow to update the todo list item using indexof array funcation in reactupdate a value in a state array react jsedit object at index in array react stateupdate a state of an array while setting the object changing an arrays element in stateupdate array of state with index reactreact update element in arrayhow can we store in state array of objectssetstate push arrayhow to update array object in reacthow to change the state of slice in jsx reactreact native update state objectedit object in array of objects react statesetstate push into arrayupdate element of state array reactupdating array in react statereact native how to update object array in state varibaleshow tro update specific item in react stateupdate object in array react nativehow to update element at position i in reactadd object to array react state at indexchange state array reacthow to add array into an array state reacthow to update the value of array in react js update state array react with indexreact setstate property of object inside arrayreact update one object in array stateupdate array state in react jsreact add object to state arraysetstate map array indexsetstate update object in arrayreact active item state on arrayhow to change value of array in sate in ractupdate array of objects react statereact change element in array statereact native how to op update object array in state variablereact setstage arrathow to track every state change in an array in reactreact update this state array with componentdidmountupdate array of objects javascript state reactupdate array in react stateupdate array element react stateset state array reactjsreact array state pushhow to update array state in react jsreact native push array examplestate update array reacthow to prevent react state from update arrayreact state update complexe arraythi setstate with apaend state array typescriptsetstate adding to arrayfinnd and update state arraychange value of array objects in state react nativechange state index arrayhow to update state array object in react jshow to use update state with arrayassigning an imported array to statechange array objects value is statereact use staet updating arrayreact detect change index of elementupdate array of statereact update value in array stringupdate an state item in arrayreact update item in arrayreact update all members of array in statestate change array at valueset state with updated arrayreact state replace array in statereactjs update array with state itemreact set state of an element in arrayreact setstate add item to arrayarray update in react statehow to change an item in object react functionreact edit state arraychanging a single value in an array of values in local state reactupdate array of objects in stateset a value of array reacrupdate state array value reactadd array state reacthow to update an array in state reacthow to update state field in array of objects reacthow to change value and update array of objects reacthow to change the value under array state in react jsupdate state in array in react jsadd object to array javascript reactupdate element in array reacthow to update an index value reactchange the array value in the state in reactupdate array state reactupdate state which is array of objects reactreact update value in arrayreact update element in array stateupdate array value reactreact js update a single state valuehow to update an object in an state array in react 3fhow to update array of state using setstate nad componentwillmount in reactmodify react state arrayreact update value in array statehow to update element object in array react jsreact changing state of arrayreact array state update itemhow to update state of an element of an array in reactappend to array state reactupdate array set stateset state with new updated array reacthow to update a whole array in state react find and replace object inside array on statereact native change array item positionhow to update state array specific index reacthow to update state of data array of objects in reactchange array object value reactupdate an object in state array ereactchange value of an array reactsetstate array indexchange state array valuereact update one item in arrayreact update state element of arrayupdate value in array reactupdating array with index setstatestate of array reactupdate only one array in statereact set array valuereact update one element in state arrayhow to update value of array in react jschange state of list in react es6react js array how to change dataupdate state array in reacthow to updatev component when i update an state arrayreact js update array in arrayarray variablt to stateupdate value in array of objects reactreact setstate arrayupdate array index set statereact state update array objectreact class component append to state arrayreact native setstate push arrayadd object to array in state reactupdating state when state is an array of objectshow to update an array object value in reactmodify element from state array reacthow to update state of an array of objects by id reactupdate value in array in state reacthow to update a value in array in reactjsupdate array rreactadd new object after current index in react jsreact updating value in state in arrayreact update array with new value reactjs set state to an arraychange value of state arraychange array in object that is a statehow to set an object using props to an empty array in react componentupdate object in array state reactpush an array of obiject in exitsting arr ay of object inn reactarray state change one elementadjust prop of item with id in stateupdate state array objectupdate state with array in reactreact update when state value is arrayreact set state array concathow to update an array element present in state in reactreact update object in array in statehow to update object value in array of object in reactupdate state of array in reactassign initial array to state reactreact js set state with an array and add to itreact native update state arrayupdate array value fromjs state in reacthow to update state that 27s an arrayhow to change array object using setstate reactupdating array item statehow to push object in array in react jsupdate the state of an arrayupdate array in the statemodify object in array setstate reactsetstate array in reacthow to update array state in usestatecopy state array reactupdating state array react indexreact state update objects in arrayi have state to update an arrayhow to set state of array in reactreact native update array valuehow to update an array in reactupdate object in array of objects reactreact update state of arrayupdating state array reactreact state object arrayreact ushow updated array of object valuehow to update array of object state in reactreact update array of satereact update object in array statereact setstate update arrayhow to update an array index in state reactreact setstate replace object in arrayget index from setstate in reactpush data to state array reactupdate array of object in react statereact update array by indexchange the state from a array of objects in reactreact update value in state arraysetstate array reactreact update array of objectspush new object to array stateupdate your array state react nativechange state of array object insdie object reactupdate element in array react stgatereact state update array of objects inside state 22usestate 22how to change value of array in state reactadd values to array in object in reactreact state update single item in arrayreact update state an object in arrayhow can i push new element to react state arrayreact state array of components elementupdate array in state with new data reacthow to push data in state array reactreact update state arraya of objectsset array of object react statereact update an array with new valuesreact add item to arraychange an array in reactupdate object in array reacthow to update react state arrayupdate an array in state reactupdate an array element in react which is in statereact update data in arrayreact how to add to state arrayadd another object to array react stateupdate a value in a state arrayupdating array of objects in react statehow to change the value of an array of state in reactupdate item in the array reactupdate array state react by indexreact state array pushupdate state array object element reacthow to set value in particular index of array using state in reactjsupdate array of object with id in react stateupdate one item array state react jshow to update an object in an array in in setstateupdate state list with key and index reactsimple state update example reactupdate array in state react via indexreact update state item in arrayreact state update array of objectsupdate value in object in array in state reactreact edit item in array in statereact update state array element field valuehow to update one object in array of state in react jscreate react array in classchange state for item in state arraychange element of state array reacgtreact upadate an array object in stateonchange update array state reactreact push objets to arraytreactjs update a element inside state arrayreact update array item in statechange the state ofa array of object using id in reactreactupdate state arrayreact setstate change array elementmodify array object in state in react nativeupdate array with stateupdate specific element in array of objects setstateupdate objects inside array reactreact state update one value in arrayreact update property of object in array in stateset state with updated arraayreact update array elementarray in object in state updatethis setstate add to arrayhow to set an array in states valuereact setstate replace object arraysetstate react array elementupdate state arrayhow to add element object in array state react jsadd element to state array reactupdate array element reactjsreactjs update state object in arrayhow to change particular index from array in react js statesupdate array item in state reactreact edit state of a arrayreact update state of array of objectsreact component in array change propertiesupdate a value in a n array that is in a react statehow to identify and update an object in a n array in state 3a reactupdate an element in an array statereact class component access state array elementhow do i update state with an arrayaraay of object not update when local object changed in reactuse setstate to update an array of objectshow to change state in object in array jsupdate array of object javascript setstatehow to add new object to array of object state reactreact update array value in statestate array object updateupdate an array inside an object in the state in reactset array object state reactreact state change a field from array of objectsupdate object inside array setstate in reactjavascript find and edit object in array stateupdating state array object reactupdate array in state with new data reacupdate element in array react statehow to setstate array in reactreact state array of objectsreact native update single item state arrayhow to update one element of an array of objects reactcomponent state wont update arrayupdate array of objects in state reactreact setstate add object to arraypush items in an empty array in react react add to array in statereact set item in array in statehow to update state array in react jshow to set new object state to a state array in react nativehow to use this setstate to update an element inside an arrayreact class compoent state array pushupdate object in array state react