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

componentRef.current Error #412

Closed
hisamafahri opened this issue Sep 8, 2021 · 2 comments
Closed

componentRef.current Error #412

hisamafahri opened this issue Sep 8, 2021 · 2 comments

Comments

@hisamafahri
Copy link
Contributor

hisamafahri commented Sep 8, 2021

I am using Next.js and trying to print a component using react-to-print.

Here's my code:

import { NextPage } from 'next'
import Head from 'next/head'
import React, { useRef } from 'react'
import ReactToPrint from 'react-to-print'
import PdfReport from '../components/PdfReport'

const Report: NextPage = () =>  {
    const componentRef = useRef()

    return (
        <div>
                <ReactToPrint
                    trigger={() => <button>Print this out!</button>}
                    content={() => componentRef.current}
                />
                <PdfReport ref={componentRef} />
        </div>
    )
}

export default Report

But I am getting the following errors:

No overload matches this call.
  Overload 1 of 2, '(props: IReactToPrintProps | Readonly<IReactToPrintProps>): ReactToPrint', gave the following error.
    Type 'undefined' is not assignable to type 'ReactInstance | null'.
  Overload 2 of 2, '(props: IReactToPrintProps, context: any): ReactToPrint', gave the following error.
    Type 'undefined' is not assignable to type 'ReactInstance | null'.

image

Any ideas how to solve this?

@hisamafahri hisamafahri changed the title componentRef Error componentRef.current Error Sep 8, 2021
@hisamafahri
Copy link
Contributor Author

hisamafahri commented Sep 8, 2021

I think this error's solution should be addressed in the docs.

Solution #401

@MatthewHerbst
Copy link
Owner

I think this error's solution should be addressed in the docs

PRs are welcome 😄

MatthewHerbst pushed a commit that referenced this issue Sep 12, 2021
Explaining solutions for problems like in the issue #401 and #412
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

2 participants