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

[Dropdown] React warning: Cannot update a component while rendering a different component (Dropdown) #6383

Closed
1 of 2 tasks
s-onuma opened this issue Jul 3, 2020 · 2 comments · Fixed by #6418
Closed
1 of 2 tasks
Assignees
Labels

Comments

@s-onuma
Copy link

s-onuma commented Jul 3, 2020

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Detailed description

Describe in detail the issue you're having.

When I call setState in a dropdown's onChange, the following warning message appears in the console.

Warning: Cannot update a component (`MyForm`) while rendering a different component (`Dropdown`). To locate the bad setState() call inside `Dropdown`, follow the stack trace as described in https://fb.me/setstate-in-render

Is this issue related to a specific component?

Dropdown

What did you expect to happen? What happened instead? What would you like to
see changed?

It's implemented appropriately and no warning message appears.

What browser are you working in?

Google Chrome (Version 83.0.4103.116)

What version of the Carbon Design System are you using?

carbon-components-react v7.15.0

What offering/product do you work on? Any pressing ship or release dates we
should be aware of?

None

Steps to reproduce the issue

  1. Select an item in a dropdown that changes the parent state in onChange
    (See the CodeSandbox attached below)
  2. The warning message appears in the console

Please create a reduced test case in CodeSandbox

CodeSandbox available:
https://codesandbox.io/s/adoring-morning-e0lt1?fontsize=14&hidenavigation=1&theme=dark

Additional information

  • Screenshots or code
  • Notes
@bavibm
Copy link

bavibm commented Jul 6, 2020

I'm having the same issue. Before I attempted to do this with hooks I was using a Class-based component and got a very similar error message just worded differently:

Cannot update during an existing state transition (such as within render). Render methods should be a pure function of props and stat

I switched to a function based component with hooks and got the error described in this post.

If we cannot update state when we select an item in a Dropdown, what is even the intended use of this component? Is there some kind of un-controlled use I'm missing?

@joshblack
Copy link
Contributor

Hey there! 👋 Was digging into this, and it seems like a side-effect of upgrading downshift. Seems like there is a specific issue that they updated in a newer version of the library so I'll go and update this dependency which should fix this problem. Just wanted to give you all a heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants