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

Shallow renderer does not support React.memo #14807

Closed
ljharb opened this issue Feb 9, 2019 · 6 comments
Closed

Shallow renderer does not support React.memo #14807

ljharb opened this issue Feb 9, 2019 · 6 comments

Comments

@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 enzymejs/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
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
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
Copy link
Collaborator

gaearon commented Feb 10, 2019

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

@aweary
Copy link
Contributor

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
Copy link
Contributor Author

ljharb commented Feb 12, 2019

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

@gaearon
Copy link
Collaborator

gaearon commented Mar 22, 2019

Fixed in 16.8.5.

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

4 participants