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

Error using @unpic/react/nextjs in a server component #642

Closed
dawaltconley opened this issue Apr 24, 2024 · 0 comments · Fixed by #646
Closed

Error using @unpic/react/nextjs in a server component #642

dawaltconley opened this issue Apr 24, 2024 · 0 comments · Fixed by #646

Comments

@dawaltconley
Copy link

Describe the bug
Importing / using @unpic/react/nextjs in an app router page/server component throws the following error.

TypeError: (0 , react__WEBPACK_IMPORTED_MODULE_2__.useContext) is not a function

It looks like the next component imports the following, which are not available to server components. See also #639

import { useContext, forwardRef, useMemo, useEffect } from "react";

For what it's worth, the default @unpic/react component seems to work as a server component.

To Reproduce
Steps to reproduce the behavior:

  1. Create an app router page app/page.tsx
  2. Try to use the nextjs component directly in the page (throws error)
  3. Wrap the nextjs component in a client component (no error)

Expected behavior
If this component is intended to be client-only, this can be fixed by adding 'use client'; to the top of the component file. If not, the component would have to avoid useContext.

Because the docs say that the component doesn't use client-side javascript, my sense is the latter solution is preferred. Otherwise, if the component is only intended for the pages router that would be good to add to the docs.

Desktop (please complete the following information):

  • OS: linux / Pop!_OS
  • Browser: Firefox
  • Version: 0.1.11
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 a pull request may close this issue.

1 participant