notFound() causing client error
Unanswered
Small Münsterländer posted this in #help-forum
Small MünsterländerOP
Using React Query, when i seem to check if the data is returned if not call
Error:
Is notFound() ssr-only?
notFound() else show pageconst { data, isFetching } = useQuery({
queryFn: async () => (await fetch(`/api/test`)).json(),
queryKey: [TEST_QUERY, id],
});
if (!data && !isFetching) notFound();
return ( Content )Error:
app-index.js:34 Warning: You are mounting a new html component when a previous one has not first unmounted. It is an error to render more than one html component at a time and attributes and children of these components will likely fail in unpredictable ways. Please only render a single instance of <html> and if you need to mount a new one, ensure any previous ones have unmounted first.Is notFound() ssr-only?
1 Reply
@Small Münsterländer Using React Query, when i seem to check if the data is returned if not call `notFound()` else show page
ts
const { data, isFetching } = useQuery({
queryFn: async () => (await fetch(`/api/test`)).json(),
queryKey: [TEST_QUERY, id],
});
if (!data && !isFetching) notFound();
return ( Content )
Error:
app-index.js:34 Warning: You are mounting a new html component when a previous one has not first unmounted. It is an error to render more than one html component at a time and attributes and children of these components will likely fail in unpredictable ways. Please only render a single instance of <html> and if you need to mount a new one, ensure any previous ones have unmounted first.
Is notFound() ssr-only?
notFound is not ssr-only but it throws an error and terminates the function, preventing it from even being rerendered, I think that’s why it doesn’t play well with react-query which probably assumes/requires that the component stays. Just wild guess though, I’m not too familiar with react-query