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

Type 'null' is not assignable to type 'ReactInstance'. #214

Closed
invious opened this issue Feb 12, 2020 · 6 comments
Closed

Type 'null' is not assignable to type 'ReactInstance'. #214

invious opened this issue Feb 12, 2020 · 6 comments

Comments

@invious
Copy link

invious commented Feb 12, 2020

getting this complaint from typescript following the hooks docs on the README

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

const QuestionSet: FunctionComponent<IQuestionSetProps> = ({ ibns }) => {

    const componentRef = useRef(null);

    return (<>
            <ReactToPrint
                trigger={() => <button>Print this out!</button>}
                content={() => componentRef.current}
            />
            {ibns.map((ibn) =>
                <Question key={ibn} ibn={ibn}/>
            )}
            </>
            )


};
@MatthewHerbst
Copy link
Owner

Thanks for reporting. I'm currently traveling, but will look into this when I get back in a few days. If you are able to find a fix, I would be happy to review a PR.

@MatthewHerbst
Copy link
Owner

Hi, sorry for not getting back to you on this. Are you still having this issue?

@MatthewHerbst
Copy link
Owner

Reading this blog post, can you try doing const componentRef<FunctionComponent> = useRef(null); and let me know if that helps? They also recommend that same approach in DefinitelyTyped: DefinitelyTyped/DefinitelyTyped#35572 (comment)

@MatthewHerbst
Copy link
Owner

Though I remind you that officially we do not support functional components right now, so I also don't know how FunctionComponent plays into what might be going on here.

@MatthewHerbst
Copy link
Owner

I was able to get a working version using React.Component when doing const componentRef<Component> = useRef(null); However, FunctionalComponent through type errors. It might be possible to resolve them but I don't have the time to look at that tonight.

@MatthewHerbst
Copy link
Owner

Going to close this for now. Let me know if the issue still exists and we can work to fix it. We are now supporting functional components with the new hook we have!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants