Skip to content
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

Add error placeholder for request errors #36

Merged
merged 1 commit into from
Mar 14, 2022
Merged

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented Mar 14, 2022

Resolves: #34

If there're errors occurred during the data fetching in useData, it will return a error property and stops hanging. Then you can use the returned error to display it or do whatever you need there. e.g.

function Example() {
  const { data, error } = useData('data', fetcher)
  return (
    <div>
      {error && <ErrorPlaceholder error={error} />}
      {data && <div>My data: {data}</div>}
    </div>
  )
}

If there's error occurred in topstories fetching it will display the below error. You can try to tweaks the fetching url to simulate an error

image

@vercel
Copy link

vercel bot commented Mar 14, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/vercel/next-rsc-news/7Mk78hePTWaxg3rAUeT6DbECSvq5
✅ Preview: https://next-rsc-news-git-error-placeholder.vercel.sh

@huozhi huozhi requested review from shuding and leerob March 14, 2022 11:19
@shuding shuding merged commit ed04fdd into main Mar 14, 2022
@huozhi huozhi deleted the error-placeholder branch March 14, 2022 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling error in data fetching
2 participants