welldone-software / why-did-you-render

why-did-you-render by Welldone Software monkey patches React to notify you about potentially avoidable re-renders. (Works with React Native as well.)
https://www.npmjs.com/package/@welldone-software/why-did-you-render
MIT License
11.2k stars 201 forks source link

Typing error on React.memo? #265

Closed bunkscene closed 1 year ago

bunkscene commented 1 year ago

I can't for the life of me figure out why I am getting this typing error:

error TS2339: Property 'whyDidYouRender' does not exist on type 'NamedExoticComponent<Props>'.

const Component = React.memo(Template, (prevProps, nextProps) => {
  ...
})
Component.whyDidYouRender = true

Any thoughts?

vzaidman commented 1 year ago

Did you try this? https://github.com/welldone-software/why-did-you-render#:~:text=In%20Typescript,%20call%20the%20file%20wdyr.ts%20and%20add%20the%20following%20line%20to%20the%20top%20of%20the%20file%20to%20import%20the%20package's%20types

Also, since when can you pass prevProps, nextProps to a functional component? Doesn't it suppose to only receive props?

bunkscene commented 1 year ago

Found out my problem. I have multiple packages and my root is in a different package than the app. So, I had the /// <reference types="@welldone-software/why-did-you-render" /> in my root package, but it was missing in the app package. It was hard to track down because the IDE had no issues with this, but tsc did!