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

ClickAwayListener throws error "Cannot update a component (MyComponent) while rendering a different component" #21542

Closed
2 tasks done
Emad-Emami opened this issue Jun 22, 2020 · 1 comment
Labels
component: ClickAwayListener The React component status: waiting for author Issue with insufficient information

Comments

@Emad-Emami
Copy link

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Since the onClickAway() is getting called in the main render function if any setState be inside this function we'll get this warning:
Screen Shot 2020-06-22 at 10 49 27 AM
https://github.com/mui-org/material-ui/blob/4e4ae0e0017dad22166658281b42716114daaef8/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js#L89
(ps: the Popper is not the MuiPopper in this picture, it's customized popper which I used ClickAwayListener inside it)

Expected Behavior 🤔

It should not throw an error.
I suggest to call this function inside an useEffect and avoid calling it inside the main function.

Context 🔦

I'm trying to use it inside a customized popper.

Your Environment 🌎

Tech Version
Material-UI v4.10.2
React 16.13.1
Browser Chrome(Latest)
TypeScript
etc.
@Emad-Emami Emad-Emami added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 22, 2020
@oliviertassinari
Copy link
Member

t should not throw an error.
I suggest to call this function inside an useEffect and avoid calling it inside the main function

@Emad-Emami Do you have a reproduction? AFAIK, onClickAway is never called inside a render method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ClickAwayListener The React component status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

2 participants