Kindly refer to the codesandbox link for code.
Basically the input is lagging by one key press although I explicitly added the compute function in the callback of setState.
Edit: I understand the solution but I want to know why this is happening since I calling the function in the callback of setState.