question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot update a component while rendering a different component warning for Modal component for React v16.13.0

See original GitHub issue

I am receiving this warning for the react modal, and upon closer inspection, I realised that it is also present on the official CodeSandBox demo, just view the console when you click the button.

Warning: Cannot update a component (ForwardRef(Modal)) while rendering a different component (ForwardRef(Fade)). To locate the bad setState() call inside ForwardRef(Fade), follow the stack trace as described in https://fb.me/setstate-in-render in ForwardRef(Fade) (at demo.tsx:83) in Unstable_TrapFocus (created by ForwardRef(Modal)) in div (created by ForwardRef(Modal)) in ForwardRef(Portal) (created by ForwardRef(Modal)) in ForwardRef(Modal) (at demo.tsx:71) in div (at demo.tsx:67) in SpringModal (at index.tsx:6)

Some research I have done on the topic include reading up on the long tag on the React Github page, as well as mention of this new warning on React’s website.

Any idea how to remove this warning?

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
qiweiiicommented, Aug 19, 2021

@oliviertassinari the two react-spring codesandbox examples mentioned above are still not working, now it show ModuleNotFoundError Could not find module in path: 'react-spring/web.cjs', a fix is to import react-spring instead of react-spring/web.cjs.

1reaction
eps1loncommented, Oct 20, 2020

I think we have to go with a transition model rather than a spring model: https://codesandbox.io/s/material-demo-forked-xu097?file=/demo.tsx

On a related note: The Backdrop produces a bit of any annoying UX where you close the modal and during the transition you’re not able to click the screen. We can fix this by disabling pointer-events when the Backdrop isn’t open. I’ll experiment with it and see if I can put together a PR that illustrates the issue properly and proposes a fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot update a component while rendering a ... - GitHub
Cannot update a component while rendering a different component warning for Modal component for React v16.13.0 #23176.
Read more >
Cannot update a component while rendering a different ...
This warning was introduced since React V16.3.0. If you are using functional components you could wrap the setState call into useEffect.
Read more >
How to fix the "cannot update a component while rendering a ...
While working on a React / Next.js application I got this error: Cannot update a component (`App`) while rendering a different component.
Read more >
cannot update a component while rendering a ... - You.com
In short, you cannot call parent's setState() outside useEffect() while in first rendering, or the error message will come up. Open side panel....
Read more >
React v18.0 – React Blog
React may start rendering an update, pause in the middle, ... In an upcoming minor, we're planning to add a new component called...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found