Use instead of hardcoded value when setting state in nested array

I have a nested array i add dynamically to my state and therefore i dont know the key/name of the nested array and I can not give the key/name of the nested array when i need to add, update, iterate or remove somethings in the array. An example is the function addClick

  const addClick = (event) => {
    // setValue({ [...value.(, ""] });
    setValue({ DevOps: [...value.DevOps, ""] });

The comment contains the way i am thinking it should be. So instead of writing "DevOps" which is the key/name of the array, i want it to use the value of "", but it will not use it. So how do i use the value when setting state of "value"??

other examples:

  const removeClick = (event) => {
    //let vals = [...value.(];
    let vals = [...value.DevOps];
    let index = Number(;
    vals.splice(index, 1);
    // setValue({ vals });
    setValue({ DevOps: vals });
{/*value.(input[form].name).map((el, i) => ( */ }
    {, i) => (
           <div key={i}>
             handleChange={(event) => handleChange(event, input[form].input_type)}

>Solution :

Close. Using a variable/expression/etc. as a property name in an object literal requires bracket notation:

setValue({ []: [...value[], ""] });


setValue({ []: vals });

Leave a Reply