Warning: Cannot update a component (XXX) while rendering a different component
See original GitHub issueWhat you were expecting:
No warning.
What happened instead:
A state change in a TextField provokes a console warning (see at the bottom of the post.)
Steps to reproduce:
For some unknown reason, the warning does NOT appear on codesandbox:
https://codesandbox.io/s/cool-curie-szq97
However if you do File > Export to ZIP and then execute the same code on your local browser, you (hopefully) get the warning.
-
Execute on your local browser.
-
Go to the
CreatePage. -
Open your console.
-
Write a letter inside the
Languageinput. -
A warning should appear.

This may be something with the validation:
validate={validateTemplate}
If this attribute is removed from the TextInput, then the warning does not appear…
Really strange…
Environment
- React-admin version: 3.4.0 (also on 3.3.3 and 3.0.0)
- Last version that did not exhibit the issue (if applicable): /
- React version: 16.13.1
- Browser: Chrome & Firefox
- Stack trace (in case of a JS error):
Warning: Cannot update a component (`XXX`) while rendering a different component (`TextInput`). To locate the bad setState() call inside `TextInput`, follow the stack trace as described in https://fb.me/setstate-in-render
in TextInput (at word-editor.tsx:45)
in div (created by Styled(MuiBox))
in Styled(MuiBox) (at word-editor.tsx:43)
in div (created by Styled(MuiBox))
in Styled(MuiBox) (at word-editor.tsx:39)
in div (created by Styled(MuiBox))
in Styled(MuiBox) (at word-editor.tsx:38)
in div (created by Styled(MuiBox))
in Styled(MuiBox) (at word-editor.tsx:37)
in XXX (at word-editor.tsx:74)
in form (at word-editor.tsx:73)
in FormView (created by ReactFinalForm)
in ReactFinalForm (created by FormWithRedirect)
in FormWithRedirect (at word-editor.tsx:66)
in WordCreatorForm (at word-editor.tsx:86)
in div (created by ForwardRef(Paper))
in ForwardRef(Paper) (created by WithStyles(ForwardRef(Paper)))
in WithStyles(ForwardRef(Paper)) (created by ForwardRef(Card))
in ForwardRef(Card) (created by WithStyles(ForwardRef(Card)))
in WithStyles(ForwardRef(Card)) (created by CreateView)
in div (created by CreateView)
in div (created by CreateView)
in CreateView (created by Create)
in Create (at word-editor.tsx:85)
in WordCreator (at word.tsx:28)
in WordCreate (created by WithPermissions)
in WithPermissions (created by Context.Consumer)
in Route (created by ResourceRoutes)
in Switch (created by ResourceRoutes)
in ResourceRoutes (created by Resource)
in Resource (at App.tsx:97)
in Route (created by RoutesWithLayout)
in Switch (created by RoutesWithLayout)
in RoutesWithLayout (created by Context.Consumer)
in div (created by Layout)
in main (created by Layout)
in div (created by Layout)
in div (created by Layout)
in Layout (created by WithStyles(Layout))
in WithStyles(Layout) (created by Context.Consumer)
in withRouter(WithStyles(Layout)) (created by ConnectFunction)
in ConnectFunction (created by LayoutWithTheme)
in ThemeProvider (created by LayoutWithTheme)
in LayoutWithTheme (created by Context.Consumer)
in Route (created by CoreAdminRouter)
in Switch (created by CoreAdminRouter)
in div (created by CoreAdminRouter)
in CoreAdminRouter (created by Context.Consumer)
in Route (created by CoreAdminUI)
in Switch (created by CoreAdminUI)
in CoreAdminUI (created by AdminUI)
in AdminUI (created by Admin)
in Router (created by ConnectedRouter)
in ConnectedRouter (created by Context.Consumer)
in ConnectedRouterWithContext (created by ConnectFunction)
in ConnectFunction (created by CoreAdminContext)
in TranslationProvider (created by CoreAdminContext)
in Provider (created by CoreAdminContext)
in CoreAdminContext (created by AdminContext)
in AdminContext (created by Admin)
in Admin (at App.tsx:60)
in App (at src/index.tsx:7)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Can not update a component while rendering a different ...
Warning : Cannot update a component (`AuthProvider`) while rendering a different component (`RequireAuth`). To locate the bad setState() call ...
Read more >Warning: Cannot update a component (`xxx`) while rendering ...
I just had: Warning: Cannot update a component from inside the function body of a different component.
Read more >cannot update a component while rendering a ... - You.com
=> I get the warning on the console "Warning: Cannot update a component (SomeChild) while rendering a different component (SomeParent). To locate the...
Read more >cannot update a component (yyy) while rendering a different ...
Coding example for the question Cannot update a component (xxx) while rendering a different component (yyy)-Reactjs.
Read more >Warning: Cannot update during an existing state transition ...
[image] 点击添加就会报错增加不了 import React, { Component } from 'react' export default class Twocomponent extends Component ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

On
react-final-form6.4.0 andfinal-form4.19.1, encountering same issue as https://github.com/marmelab/react-admin/issues/4665#issuecomment-611579207. Movingvalidate={required()}fromSelectInputup toReferenceInput(as per the same comment) fixes it.I have this issue whenever i put my validation on a input within a referenceinput. ex:
<ReferenceInput label="Address type" resource="addresstypes" source="addressTypeId" reference="addresstypes"><SelectInput optionText="name" validate={required()} /></ReferenceInput>throws the warning while<ReferenceInput label="Address type" resource="addresstypes" source="addressTypeId" reference="addresstypes" validate={required()} ><SelectInput optionText="name" /></ReferenceInput>does not