Skip to content

Warn if calling setState in getChildContext #6114

@blainekasten

Description

@blainekasten

This code causes a maximum call stack:

getChildContext() {
  this.setState({
    foo: 'bar',
  });

  return {
    foo: this.state.foo,
  };
}

These sort of errors are hard to track down as the stack trace is deep in react. Is this a place we can give a user an invariant to let them know what they did wrong?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions