Skip to content

[BUG] Setting state in onError leads to React warning about setState called during render #872

@lilactown

Description

@lilactown
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • I have read the documentation and cannot find an answer.

Describe the bug
When passing a state setter to the onError prop of MDXEditor, React prints a warning similar to

hook.js:608 Cannot update a component (`DocumentPage`) while rendering a different component (`RealmWithPlugins`). To locate the bad setState() call inside `RealmWithPlugins`, follow the stack trace as described in https://react.dev/link/setstate-in-render

Reproduction
https://stackblitz.com/edit/github-qekvbmto?file=package.json

To Reproduce
Steps to reproduce the behavior:

  1. Navigate to the link above
  2. Open dev console

Expected behavior
No errors or warnings are presented to the developer in the console

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome

Additional context
My hunch is this is due to the way gurx propagates values on change- perhaps instead of calling onError directly in the signal setup in the core plugin, using an effect would stop this from happening.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions