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

Nextjs support #59

Open
saipranay47 opened this issue Sep 23, 2021 · 7 comments
Open

Nextjs support #59

saipranay47 opened this issue Sep 23, 2021 · 7 comments

Comments

@saipranay47
Copy link

Giving this error while using Nextjs

image

@anuraglol
Copy link

Hey there

I'm getting the same error..did you found any solution.. Or any alternative to download dom as image?

@Brandyweb
Copy link

@kr-anurag @saipranay47 Yoou can use so

const exportImageRef = useRef();

React.useEffect(() => {
  if (typeof window !== undefined) {
     import('react-component-export-image').then(
       module => (exportImageRef.current = module)
     )
  }
}, [])

and to call the methods

const onDownload = () => {
  return exportImageRef.current?.exportComponentAsJPEG(ref)
}

Original Issue: #42

@SlayerAnsh
Copy link

SlayerAnsh commented Nov 12, 2021

Hey there,
I came across this problem while building a project in nextjs. Nextjs provides dynamic import which you can use to disable ssr.

For more information follow official docs. Here

Sample Code from docs:

import dynamic from 'next/dynamic'

const DynamicComponentWithNoSSR = dynamic(
  () => import('../components/hello3'),
  { ssr: false }
)

function Home() {
  return (
    <div>
      <Header />
      <DynamicComponentWithNoSSR />
      <p>HOME PAGE is here!</p>
    </div>
  )
}

export default Home

Edit:
You can now use the library inside NoSSR Component (in this case ../components/hello3) and it wont give to error.

@detautama
Copy link

Hey there, I came across this problem while building a project in nextjs. Nextjs provides dynamic import which you can use to disable ssr.

For more information follow official docs. Here

Sample Code from docs:

import dynamic from 'next/dynamic'

const DynamicComponentWithNoSSR = dynamic(
  () => import('../components/hello3'),
  { ssr: false }
)

function Home() {
  return (
    <div>
      <Header />
      <DynamicComponentWithNoSSR />
      <p>HOME PAGE is here!</p>
    </div>
  )
}

export default Home

Edit: You can now use the library inside NoSSR Component (in this case ../components/hello3) and it wont give to error.

I got this error when trying import it
image

"react-component-export-image": "^1.0.6",
"next": "12.0.7",

@detautama
Copy link

This is work for me:

  <button onClick={async () => {
              const { exportComponentAsPNG } = await import('react-component-export-image')
              exportComponentAsPNG(componentRef)
        }}>
    Download as PNG
</button>

@danielcranney
Copy link

Thanks @detautama. Does this work for you on mobile devices? I'm trying to download on Chrome (on iPhone) and it doesn't download an image, just a file called 'download'.

@SirMajed
Copy link

This is work for me:

  <button onClick={async () => {
              const { exportComponentAsPNG } = await import('react-component-export-image')
              exportComponentAsPNG(componentRef)
        }}>
    Download as PNG
</button>

Thank you so much

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

No branches or pull requests

7 participants