React: Shallow renderer does not support React.memo

Created on 9 Feb 2019  路  6Comments  路  Source: facebook/react

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 https://github.com/airbnb/enzyme/pull/1914, in which tests are failing with Cannot call a class as a function. (it's tough to repro stuff with the shallow renderer)

Shallow Renderer Feature Request

Most helpful comment

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

All 6 comments

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.

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

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

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

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

Fixed in 16.8.5.

Was this page helpful?
0 / 5 - 0 ratings