I have a handler that changes some state of my react application, let's say it shuffles state entry data
:
state = {
data:[1,2,3,4,5]
};
public handleShuffle = () => {
const current = this.state.data;
const shuffled = current
.map((a: any) => [Math.random(), a])
.sort((a: any, b: any): any => a[0] - b[0])
.map((a: any) => a[1]);
this.setState({
...this.state,
data: shuffled
});
consoleLog(this.state.data[0])
};
Is there a way to access this new shuffled array still in this handler so there is a log of not 1 which is previous state, but a new shuffled one?