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. Probably due to bad setState()

See original GitHub issue

Describe the bug React issues a warning about bad setState when the Carousel component is used

To Reproduce Steps to reproduce the behavior:

  1. Install 10.2.0
  2. Install react-carousel 2.0.3
  3. Dynamic import the carousel component like so (as NextJS SSR crashes using normal import)
import dynamic from 'next/dynamic';

const Carousel = dynamic(
  () => import('@brainhubeu/react-carousel'),
  { ssr: false },
);
  1. Use the carousel
  2. See error in Chrome console

Expected behavior A clear and concise description of what you expected to happen.

Screenshots image

Environment

System:
    OS: Windows 10 10.0.19042
    CPU: (4) x64 Intel(R) Core(TM) i5-7600 CPU @ 3.50GHz  
    Memory: 1.43 GB / 7.94 GB
  Binaries:
    Node: 16.0.0 - C:\Program Files\nodejs\node.EXE       
    npm: 7.10.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 90.0.4430.212
    Edge: Spartan (44.19041.906.0), Chromium (90.0.818.56)
    Internet Explorer: 11.0.19041.1
  npmPackages:
    @brainhubeu/react-carousel: 2.0.3 => 2.0.3

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

5reactions
shaunstoltzcommented, Jun 17, 2021

Hi, sorry I abandoned this in favor of https://github.com/akiran/react-slick that just seems to work our of the box

0reactions
tramaxcommented, Jun 17, 2021

I got this working by used the source and removing all the scss imports as they were bugging in my build environment. Simple import of the index.js file from the src directory here https://github.com/brainhubeu/react-carousel/tree/master/react-carousel/src and the errors about setState were resolved.

Hi Shaun. Do you use dynamic import via 'next/dynamic'? Would you be able to post a screenshot or a snippet of your code? Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot update a component while rendering a different ...
I fixed this issue by removing the dispatch from the register components render method to the componentwillunmount method. This is because ...
Read more >
Cannot update a component (`xxx`) while rendering ...
The Batcher 's component's setState is the state setter that is being called, and the main cause is because replaceState from RecoilRoot is ......
Read more >
Cannot update a component while rendering a different ...
The fix is fairly simple. Just wrap the condition check in the useEffect. This hook basically tells React that the component has to...
Read more >
react native cannot update a component while rendering ...
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 >
Drum Machine / Cannot update a component (`App`) while ...
Warning: Cannot update a component ( App ) while rendering a different component ( Pad ). To locate the bad setState() call inside...
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