Search
Search-as-you-type with the race condition solved by construction. switchMap cancels the previous search whenever a new keyword arrives. A slow response for an old keyword can never overwrite fresh results.
This demo makes shorter keywords slower on purpose. Type quickly and watch stale responses lose.
The hook split:
- The input reads
useSyncObservable. Controlled inputs need synchronous updates. - The results read
useObservable. Its built-in deferral keeps typing responsive while results render.
For the Suspense-integrated version of this comparison, see Suspense & deferred values.
Last updated on