Warning: Cannot update a component (`xxx`) while rendering a different component (`xxx`).
See original GitHub issueA warning is occured where useRecoilValue() is used even though I write a code like one which is in the official document here.
this is my code
import React, { useEffect } from 'react';
import { atom, useRecoilState, useRecoilValue, selector } from 'recoil';
function RecoilApp() {
useEffect(() => {
console.log('test');
});
return(
<div>
Recoil App
<TextInput />
<CharCount />
</div>
);
}
const textState = atom({key: 'textState', default: ''});
function TextInput() {
const [text, setText] = useRecoilState(textState);
const onChange = event => {
setText(event.target.value);
}
return(
<div>
<input type="text" value={text} onChange={onChange} />
<br />
Echo: {text}
</div>
);
};
function CharCount() {
const count = useRecoilValue(countState);
return <>Charset Count: {count}</>;
}
const countState = selector({
key: 'countState',
get: ({get}) => {
const text = get(textState);
return text.length;
},
});
export default RecoilApp;
Issue Analytics
- State:
- Created 3 years ago
- Reactions:149
- Comments:85 (10 by maintainers)
Top Results From Across the Web
Warning: Cannot update a component (XXX) while rendering ...
No warning. What happened instead: A state change in a TextField provokes a console warning (see at the bottom of the post.) Steps ......
Read more >Cannot update a component (xxx) while rendering a different ...
In my react app, I'm getting this strange error ("Cannot update a component (xxx) while ...
Read more >cannot update a component while rendering a ... - You.com
I am getting this warning in react: index. js:1 Warning: Cannot update a component (`ConnectFunction`) while rendering a different component (`Register`).
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
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop 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
Top GitHub Comments
I’m working on a big refactor where dependencies will not go through React state at all. That will fix this (and make it a lot more efficient, and is needed for CM). In the meantime I don’t see a an obvious workaround unfortunately.
Thanks for reporting, I am investigating this.