Skip to content

Implement a catch if useSWR returns error #730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jtucholski opened this issue Feb 7, 2025 · 2 comments
Open

Implement a catch if useSWR returns error #730

jtucholski opened this issue Feb 7, 2025 · 2 comments

Comments

@jtucholski
Copy link
Contributor

If useSWR returns an error, we should return some sort of element to display this error to inform the user. This may be implemented in some pages, but not all. This should apply to all components that use useSWR.

@jtucholski jtucholski assigned jtucholski and unassigned jtucholski Feb 7, 2025
@jtucholski
Copy link
Contributor Author

jtucholski commented Feb 7, 2025

@calisio Would an example of a page that properly handles this be Favorites.tsx? I have noticed that not all pages use the error.

            {isLoading && <p>Loading...</p>}
            {error && (
                <p className="text-error">
                    Failed to load favorites: {error.message}
                </p>
            )}
            {!isLoading && !error && favorites.length === 0 && (
                <h2>No favorites found.</h2>
            )}
            {!isLoading && !error && meta && (
                <div className="flex justify-center">
                    <Pagination
                        meta={meta}
                        setPage={setPageQuery}
                        setPerPage={handleSetPerPage}
                    />
                </div>
            )}

@calisio
Copy link
Contributor

calisio commented Feb 10, 2025

Yes, we should have a component that can be used across all pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants