I am building a game of life with React. When I set "alive" cells by clicking on them 1-2 times per second it works fine, but when I try to click faster there is an error:
"TypeError: Cannot read property 'undefined' of undefined".
Error pointing to the fourth line of functional expression:
const onClick = (e) => {
const indexies = e.target.id.split(",");
const x = indexies[0];
const y = indexies[1];
setGrid([...grid], (grid[x][y] = !grid[x][y])); //error line
};