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 rendering with React.memo #17440

Closed
henryqdineen opened this issue Nov 23, 2019 · 3 comments
Closed

Shallow rendering with React.memo #17440

henryqdineen opened this issue Nov 23, 2019 · 3 comments
Labels
Resolution: Stale Automatically closed due to inactivity

Comments

@henryqdineen
Copy link
Contributor

I understand that the future of react-test-render/shallow is uncertain but I thought I would log this issue anyway. It looks like components wrapped in React.memo will not re-render unless props changed. In our case the component is using the useState hook and updating state does not re-render when using wrapped in React.memo()

if (isMemo(element) && previousElement !== null) {
// This is a Memo component that is being re-rendered.
const compare = element.type.compare || shallowEqual;
if (compare(previousElement.props, element.props)) {
shouldRender = false;
}
}

Contrived codesandox example:

https://codesandbox.io/s/sweet-field-ydm0c?fontsize=14&hidenavigation=1&module=%2Fsrc%2Findex.test.js&previewwindow=tests&theme=dark

@bdwain
Copy link

bdwain commented Dec 18, 2019

this is mentioned in #17278 and is fixed in enzymejs/enzyme#2300

@stale
Copy link

stale bot commented Mar 18, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Mar 18, 2020
@gaearon
Copy link
Collaborator

gaearon commented Mar 18, 2020

Please feel free to file this in https://github.com/NMinhNguyen/react-shallow-renderer.

@gaearon gaearon closed this as completed Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

No branches or pull requests

3 participants