gregrickaby/viewer-for-reddit

Fix Race Conditions

gregrickaby opened this issue · 1 comments

Problem: If user types to fast in the search, the app just crashes.

The "fetch as you type" is the UX I want, but there needs some delay added, since the hooks are setup to fetch with each keystroke. This is apparently a common problem, and I found some blog posts:

This has been fixed with 9d68603

To help simplify things (for me, I'm still learning React Hooks) I dumped the useForm and useFetch. I read some blog posts, and found this https://usehooks.com/useDebounce/ which led me to https://codesandbox.io/s/711r1zmq50?file=/src/index.js:1135-1163