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

Shallow renderer does not support React.memo #14807

Open
ljharb opened this Issue Feb 9, 2019 · 5 comments

Comments

Projects
None yet
4 participants
@ljharb
Copy link
Contributor

ljharb commented Feb 9, 2019

Do you want to request a feature or report a bug?
bug

What is the current behavior?
In normal rendering, you can memoize a class-based component: https://jsfiddle.net/586ea3cx/

With the shallow renderer, it seems like you can't: https://jsfiddle.net/odj217Lv/1/

This might be blocking airbnb/enzyme#1914, in which tests are failing with Cannot call a class as a function. (it's tough to repro stuff with the shallow renderer)

@Yurickh

This comment has been minimized.

Copy link
Contributor

Yurickh commented Feb 9, 2019

I would like to point out that React.memo being used with classes is not documented behaviour and might not be part of React's public facing API.

You can check that all references to React.memo in the docs say it is meant to be used with functional components here and here.

@ljharb

This comment has been minimized.

Copy link
Contributor Author

ljharb commented Feb 9, 2019

Indeed; but it doesn’t throw when you try, and it seems to work fine in actual React - I’d expect it to work, or not work, the same everywhere.

@gaearon

This comment has been minimized.

Copy link
Member

gaearon commented Feb 10, 2019

memo() can be used with any component type. Happy to take a PR that adds support for it!

@aweary

This comment has been minimized.

Copy link
Member

aweary commented Feb 10, 2019

This doesn't seem to be isolated to class components, it fails with any component using memo(): https://jsfiddle.net/f0j1e5tw/6/

@aweary aweary changed the title shallow renderer does not support `React.memo(ClassComponent)` Shallow renderer does not support React.memo Feb 10, 2019

@ljharb

This comment has been minimized.

Copy link
Contributor Author

ljharb commented Feb 12, 2019

The relevant tests in the open enzyme PR only fail for class components, fwiw.

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