score:1

Accepted answer

setting state in react is always async. that means history will not be updated until the next render.

either you should pass squares into didsomeonewin and use it to determine a winner:

function squareclick(i){
  // code
  didsomeonewin(squares)
}
function didsomeonewin(squares) {
 // remove line fetching squares from history
 // code
}

or the call to didsomeonewin should happen in a useeffect that runs after each render:

useeffect(() => { didsomeonewin(); }, [history]);
// and add history as the dependency, so we only run `didsomeonewin` if history changes

Related Query

More Query from same tag