Skip to content

Instantly share code, notes, and snippets.

@dwalkr
Created June 4, 2020 16:23
Show Gist options
  • Save dwalkr/0456a0aee8e2dfa715642a3f5995a71a to your computer and use it in GitHub Desktop.
Save dwalkr/0456a0aee8e2dfa715642a3f5995a71a to your computer and use it in GitHub Desktop.
useEffect(() => {
setHasError(false)
if (!editMode) {
import(`../content/${slug}.json`)
.then((content) => {
setContent(content.default)
})
.catch((e) => {
setHasError(true)
})
} else {
// TODO now we're loading this data 2x when in edit mode
loadData().then((result) => {
if (result && result.error) {
setHasError(true)
}
})
}
}, [slug, setContent, setHasError, editMode])
if (hasError) {
return <NotFound />
}
//... return page component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment