-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Description
Recommend React's hooks does not gracefully handle errors, and errors cannot be caught in React's ErrorBoundary.
For more context :
We are using Algolia's recommend on production and staging environment.
The production environment's index works. The staging environment's index does not build as it has not enough data (less than 1'000 events).
However, when we are running our tests against the staging env, all requests fail because the index does not exists (as it cannot build). The problem, is that all errors cannot be caught and results in React throwing an error.
For instance, in useFrequentlyBoughtTogether.js line 42 :
useEffect(() => {
setStatus('loading');
getFrequentlyBoughtTogether({
// ...
})
.then((response) => {
setResult(response);
setStatus('idle');
})
// missing catch, resulting in error not being catch by React
}, [
// ...
]);It would be great to gracefully handles errors in each hook.
Reproduction
The linked codesandbox does not work. It results with an error /app.tsx: Unexpected token (133:105).
Steps
To reproduce the error, you may :
- Configure recommendClient with a wrong client
- Use an index that does not build
- Ask for a non-existent objectIDs
Expected behavior
Error should be gracefully handled by React / hooks.
Environment
- OS: macOS
- Browser: Chrome
- Library version: 4.14.3