2

Nextjs throws an error: Error: Invalid hook call. Hooks can only be called inside of the body of a function component.

Whenever I try to access useContext Value in getStaticPaths() function.

Here's my code:

export async function getStaticPaths() {

  const { videos } = useVideos();

  const paths = videos.map((video: any) => {
    return {
      params: { id: video.videoId },
    };
  });

  return {
    paths,
    fallback: false,
  };
}
juliomalves
  • 42,130
  • 20
  • 150
  • 146
  • 2
    You can't use hooks inside `getStaticPaths` as it's just a regular function - [React hooks](https://reactjs.org/docs/hooks-intro.html) can only be used in React function components and/or other React hooks. – juliomalves Dec 20 '21 at 16:58

0 Answers0