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

Not working with forwardRef #161

Closed
mrondra opened this issue Nov 26, 2020 · 3 comments
Closed

Not working with forwardRef #161

mrondra opened this issue Nov 26, 2020 · 3 comments

Comments

@mrondra
Copy link

mrondra commented Nov 26, 2020

Hi,

I have a problem with forwardRef and Typescript. Example below:

const Heading = forwardRef<HTMLHeadingElement, HeadingProps>(function headingFunction(
    props: HeadingProps,
    ref,
): ReactElement<HeadingProps, HeadingProps['tag']> | null {
    ...
});

Heading.whyDidYouRender = true;     

And I get this error:

TS2339: Property 'whyDidYouRender' does not exist on type 'ForwardRefExoticComponent  >'

Do you have any idea what to do with it?

Thank you

@vzaidman
Copy link
Collaborator

vzaidman commented Nov 27, 2020

Ok i've found the problem.
add

/// <reference types="@welldone-software/why-did-you-render" />

to the top of wdyr.tsx. f.e.:

/// <reference types="@welldone-software/why-did-you-render" />
import React from 'react';

if (process.env.NODE_ENV === 'development') {
  const whyDidYouRender = require('@welldone-software/why-did-you-render');
  whyDidYouRender(React, {
    trackAllPureComponents: true,
  });
}

@mrondra
Copy link
Author

mrondra commented Nov 27, 2020

Great, it works, thank you very much.

@vzaidman
Copy link
Collaborator

somehow, it was adding the types automatically up until now.

however, it seems like we need to add it manually in the latest typescript versions.

I'm adding a section about it in the readme.

thanks for noticing and reporting the problem!

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