score:0

Accepted answer

you can change the value at the index and set the state variable again:

const handlechange = (index, value) => {
  const data = [...polldata]
  data.splice(index, 1, value) /* or data[index] = value */
  setpolldata(data)
}

polldata && polldata.map((entry, index) => {
        return(
          <div classname="input-group mb-2" key={index}>   
           <input placeholder={"option " + index} classname="form-control" value={entry} onchange={(e) => handlechange(index, e.target.value)}}></input>
           <button tabindex="-1" classname="btn btn-outline-danger" onclick={() => handledelete(index)}> x </button>
          </div>
      )
 })

you shouldn't mutate the state variable directly. if it is an object or an array, make a copy of it, alter the copy as you wish and set the state variable to the altered copy.


Related Query

More Query from same tag