How to update the state the correct way

hi, can anyone tell me how to update the state the correct way ?
I am working on movie search project I have movie cards and an input field for filtering out movies according to input, filter is working but it is 1 step backward, I mean "when I type “a” in input , it doesn’t filter and when I remove “a” it filter the movies according to word “a”.
here is my project link
thanks in advance

you have lots of files in there, can you give more details on where to find the issue or the involved components?

That’s because setState is asynchronous so it’s not going to wait use the new state values in the second setState of your onclick handler.

If you want a side effect to happen when state changes, you should use useEffect with the dependency array being the state that got changed from your onclick function.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.