0

In this case I've and array by using useState

const [acts, setActs] = useState([])

now the point is that I want to push item at 4th index in array, and it should look like this

['', '', '', '' ,'should be here', '', '']

So, the method I'm trying to do this is here

let actsArray = []
const [acts, setActs] = useState(actsArray)

const addItem = (index) => {
   actsArray.splice(index, 0, 'Should be here')
   setActs(actsArray)
}
Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Ahmed Shaikh
  • 106
  • 8
  • There's also this question about Redux, but the strategy is really similar: [How to update single value inside specific array item in redux](https://stackoverflow.com/q/35628774/1218980) – Emile Bergeron Sep 20 '21 at 18:44
  • 1
    Thanks for reference @Emile. I've got my problem solved! – Ahmed Shaikh Sep 20 '21 at 21:46

0 Answers0