score:2

Accepted answer

have setreadyarray use a callback instead of using the readyarray in the closure - this way, immediate state updates won't overwrite each other:

const setready = (val, idx) => {
  setreadyarray(readyarray => readyarray.map(
    (orig, i) => i === idx ? orig : val
  ));
};

Related Query

More Query from same tag