react-exercises | Exercise DB with React & Material-UI | User Interface library
kandi X-RAY | react-exercises Summary
kandi X-RAY | react-exercises Summary
Exercise DB with React & Material-UI
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of react-exercises
react-exercises Key Features
react-exercises Examples and Code Snippets
Community Discussions
Trending Discussions on react-exercises
QUESTION
My application has a user input a query to make a request to the Pokemon API and the response data is rendered.
If a user inputs a query that doesn't exist in the database, it will trigger the error boundary and a Try Again
button to recover from the error by resetting the query state and have the user resubmit a different query. This is the intended behavior.
However, with my current setup, when the user's query does not have any matches, the console will show GET https://pokeapi.co/api/v2/pokemon/foo 404
and Uncaught (in promise) Error: Request failed with status code 404
. The user does not see this error though. Nothing to tell the user that their query does not have any matches. I'm aiming to have a more explicit user experience telling the user their submitted request does not have any matches and to click the Try Again
button to reset the input and submit a new query. I believe, this is what the error boundary should be doing.
I'm using the following libraries: React Query, React Hook Form, React Error Boundary
. I've been suggested to use React Query's onError
callback for logging errors and set the property useErrorBoundary: true
. Still no luck.
Here's a working example to demonstrate the intended behavior. https://epic-react-exercises.vercel.app/react/hooks/3
Here's my attempt. Please let me know how to solve this. https://codesandbox.io/s/pokedex-5j1jf
...ANSWER
Answered 2021-Mar-26 at 14:05I think the problem comes from the way you are using the error boundary.
If we look at the docs of react-error-boundary, we see the following:
The simplest way to use is to wrap it around any component that may throw an error. This will handle errors thrown by that component and its descendants too.
In your example the component that throws the error is the component that renders the ErrorBoundary
. But in order for this to work, the component that throws the error should be a child of the ErrorBoundary
.
I created a slightly different sandbox to illustrate this. https://codesandbox.io/s/jovial-poincare-06e6v
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install react-exercises
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page