array of object react js useState

// sample datas structure
/* const datas = [
    {
      id:   1,
      name: 'john',
      gender: 'm'
    }
    {
      id:   2,
      name: 'mary',
      gender: 'f'
    }
] */ // make sure to set the default value in the useState call (I already fixed it)

const [datas, setDatas] = useState([
    {
      id:   1,
      name: 'john',
      gender: 'm'
    }
    {
      id:   2,
      name: 'mary',
      gender: 'f'
    }
]);

const updateFieldChanged = index => e => {

    console.log('index: ' + index);
    console.log('property name: '+ e.target.name);
    let newArr = [...datas]; // copying the old datas array
    newArr[index] = e.target.value; // replace e.target.value with whatever you want to change it to

    setDatas(newArr); // ??
}

return (
    <React.Fragment>
        { datas.map( (data, index) => {
              <li key={data.name}>
                <input type="text" name="name" value={data.name} onChange={updateFieldChanged(index)}  />
              </li>
          })
        }
    </React.Fragment>
)

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
array of bjects usestate update object in array react with useState how to set value in array react hook usestate react js update specific object in array hooks state react js hook update object in array state react js hook update object to array state react use state array of objects how do you use array of object in usestate how to set usestate array objects in react how to store arrays of objects in useState setstate array of objects hooks update an array inside an object react hooks update array of object in useState react update array in state react hooks set object in array react hooks react usestate array of objects usestate for array of objects update array field in state object using set hooks assign array value to new array value in state hooks react js hooks set state to array react js hooks make setting state to array usestate hook set array of object setstate hook array of objects setstate to an array of objects holding an array of objects useState React.useState&lt;Array&lt;object&gt;&gt; using useState update array of object in reactjs react hooks state array of objects usestate handle array of objects array of objects usestate usestate array of objects how to set a specific object in an object array using useState array of objects useState react array of object useState js array of objects in usestate when to use array and when to use object in usestate how to use arry of object with useState in react js react setstate of array inside object es6 using usestate how to set array object using useState in react js how to set the state to be an object or an array in react useState array of object react js useState react hooks array render changes to array in state react update usestate array of objects setState with array in react hooks setState array objects react usestate how to create the object inside an array using useState Hook in react native how to acess the array of object in the state in hooks update array of objects react hooks react hooks setState array of objects how can we inset object values in array react hooks set usestate value of elements in array of object react react hooks setstate with array setstate with array of objects update state one array objects hooks usestate set objects of array using hooks to set array state update an object item in an array react hooks react usestate update to array of objects reactjs usestate array of objects add react hooks setstate change only one property of an array setstate item in array of objects how to update arry of object in useState hook in react js\ set and array of objects usestate react useState object with array how to update arry of object in useState hook in react js update an object in an array in react hooks change value of a specific property of an array of object in react hooks state passing array of objects in usestate js hooks assign usestate to new array js hooks set usestate to new array add an object to array in react hooks useState react usestate with array of objects usestate on array of objects in react how to set array of object in usestate in react native how to set useState as array react hooks react hooks put return objects into array react hooks update state array of objects react update array state with hooks store object into an araay react usestate react hooks usestate object in array react hooks usestate update object in array change value in array of objects javascript react hooks change object inside array hooks how to update state of object containing array as property react hook usestate how to set data in array of objects useState in ract usestate with array of objects set array in objec of array hooks set array of obj react hooks react hooks put object into array react how to setState to array hooks javascript react usestate array with object how to set arry of objects in useState how to set new object state to a state array in react native hooks set array in an object using usestate how to set array of objects using useState one at a time how to set array of objects using useState set state array of objects react hooks setstate update array hooks setstate hook in aray of objects by index add object to useState array in react js react hook usestate set array of objects set a state with an array of object hooks how to update array of object using hooks in react native how to update array of object using hooks in react nartive how to update array of object using hooks in react react update state array of objects useState react setstate array of objects hooks update array of objects javascript using useState setstate in array of objects React hooks update array of objects react usestate update object replace one object in useState javascript update array of objects react hooks hcan we use array variable and a object variable in state in hooks react setting object data in useState array hook proper way to update a array in react hooks set array of object for usestate define state as array of objects in react hooks useState with array of object how to set array of objects variable in usestate how to set array of objects in usestate react hooks usestate array of objects set usestate to object array value set array object to usestate reactjs set array object to useState React update state array of objects hooks set array of object into react state using hooks set items in array to hooks react update value in object inside array state react in usestate react hooks set state array of object react setState hook object of array update object in array react hooks
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source