nygardk / react-share

Social media share buttons and share counts for React
MIT License
2.6k stars 429 forks source link

Cannot be use with React Server Component #491

Open Maxwell2022 opened 1 year ago

Maxwell2022 commented 1 year ago

React Server Side component cannot render class components.

error - node_modules/.pnpm/react-share@4.4.1_react@18.2.0/node_modules/react-share/lib/ShareButton.js (11:18) @ eval
error - Class extends value undefined is not a constructor or null

This might be caused by a React Class Component being rendered in a Server Component, React Class Components only works in Client Components. Read more: https://nextjs.org/docs/messages/class-component-in-server-component

This might be caused by a React Class Component being rendered in a Server Component, React Class Components only works in Client Components. Read more: https://nextjs.org/docs/messages/class-component-in-server-component
    at eval (webpack-internal:///(sc_server)/./node_modules/.pnpm/react-share@4.4.1_react@18.2.0/node_modules/react-share/lib/ShareButton.js:14:58)

ShareButton exports a class component

A temporary solution is to add 'use client'; in your custom Share component