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

Doesn't work with class components wrapped in React.memo #50

Closed
Hypnosphi opened this issue Jul 31, 2019 · 5 comments
Closed

Doesn't work with class components wrapped in React.memo #50

Hypnosphi opened this issue Jul 31, 2019 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Hypnosphi
Copy link
Contributor

See #10 (comment)

@Hypnosphi
Copy link
Contributor Author

It throws following exception:

TypeError: Cannot set property 'props' of undefined
    at Component (http://localhost:6006/vendors~main.317c2c034316233265a1.bundle.js:267013:14)
    at WithState (http://localhost:6006/vendors~main.317c2c034316233265a1.bundle.js:269148:33)
    at WDYRWrappedByMemoFunctionalComponent (http://localhost:6006/vendors~main.317c2c034316233265a1.bundle.js:83010:12)
    at renderWithHooks (http://localhost:6006/vendors~main.317c2c034316233265a1.bundle.js:233595:18)
    at updateFunctionComponent (http://localhost:6006/vendors~main.317c2c034316233265a1.bundle.js:235284:20)
    at updateSimpleMemoComponent (http://localhost:6006/vendors~main.317c2c034316233265a1.bundle.js:235230:10)
    at updateMemoComponent (http://localhost:6006/vendors~main.317c2c034316233265a1.bundle.js:235149:14)
    at beginWork (http://localhost:6006/vendors~main.317c2c034316233265a1.bundle.js:236346:16)
    at performUnitOfWork (http://localhost:6006/vendors~main.317c2c034316233265a1.bundle.js:239969:12)
    at workLoop (http://localhost:6006/vendors~main.317c2c034316233265a1.bundle.js:240009:24)

The reason is that WDYRWrappedByMemoFunctionalComponent calls the component as a function while in fact it is a class

@vzaidman
Copy link
Collaborator

ok i might indeed fix it. and maybe even soon but React.memo is made for functional components:
https://reactjs.org/docs/react-api.html#reactmemo

are you sure it even makes your class component pure?

@Hypnosphi
Copy link
Contributor Author

@vzaidman
Copy link
Collaborator

vzaidman commented Sep 9, 2019

added a prove that this happens (a test that fails) to the following branch:
https://github.com/welldone-software/why-did-you-render/tree/%2350-memo-a-class-component

Looks like a not too hard thing to fix, if anybody wants to try to do it.

@vzaidman vzaidman added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Sep 9, 2019
@vzaidman
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants