Hi I am trying to update a state in Reactjs just after popluating an array , but everytime it comes as an empty array. I guess this is due to async behaviour of setState, but I am unable to put my head as how to solve it.
Any help is appreciated
const [game, setgame] = useState({ row: 6, column: 6, w: 100, x: '', y: '', arr: [], placedWordsX: [], boardArray: [] })
const grid=16;
useEffect(() => {
start();
}, [])
function start() {
let newGameArr = []
for (let i = 0; i < grid; i++) {
newGameArr[i] = "-";
}
setgame({...game, arr:newGameArr})
console.log(game)
console.log(game.array) //always coming empty
}