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.

Warning: Cannot update a component (`xxx`) while rendering a different component (`xxx`).

See original GitHub issue

A warning is occured where useRecoilValue() is used even though I write a code like one which is in the official document here.

スクリーンショット 2020-05-15 4 55 26

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:open
  • Created 3 years ago
  • Reactions:149
  • Comments:85 (10 by maintainers)

github_iconTop GitHub Comments

123reactions
davidmccabecommented, May 20, 2020

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.

59reactions
davidmccabecommented, May 15, 2020

Thanks for reporting, I am investigating this.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

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