easy-peasy icon indicating copy to clipboard operation
easy-peasy copied to clipboard

Cannot update a component from inside the function body of a different component.

Open romiem opened this issue 6 years ago • 1 comments

Ever since upgrading to React 16.13.1, I have been receiving this error ([email protected]).

The stack trace seems to point the finger at easy-peasy, to this line: https://github.com/ctrlplusb/easy-peasy/blob/6e23497f294e24aee785099d6eae940d12421a0e/src/hooks.js#L79

It appears that this error is being caused when trying to setState on another component during the function component body. The react team have now deemed it a bad pattern which now throws an error.

Has anyone else had the same issue?

Some other resources on this issue: https://github.com/facebook/react/issues/18178 https://github.com/final-form/react-final-form/issues/751#issuecomment-606212893

romiem avatar May 06 '20 17:05 romiem

It appears the stack trace from Chrome Devtools was flagging a false positive.

As for the actual issue; when calling an action in the render step of a functional component (that is not triggered by a side effect) it now needs to be wrapped using useEffect as per the React 16.13.0 guidelines.

Closing this issue.

romiem avatar May 06 '20 22:05 romiem