Skip to content

data returns undefined on Details Page api/snippets/[id].js #762

Answered by NikRoe
PeetThesing asked this question in Web
Discussion options

You must be logged in to vote

Yes, that is indeed one of the issues.

You can either make the fetcher global, following the link provided by Willy, or you can also add it in the SnippetDetails Component.

You also need to fetch a different route. It should be

 const { data, isLoading, error } = useSWR(`/api/snippets/${id}`, fetcher);

There is also another small bug: In your /pages/api/snippets/[id]/index.js you are currently checking for the request.methode. This should be request.method.

Hope this already helps

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@NikRoe
Comment options

Answer selected by PeetThesing
@PeetThesing
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
3 participants