Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Cannot update a component from inside the function body of a different component. #110

Closed
Tarpsvo opened this issue Feb 28, 2020 · 2 comments

Comments

@Tarpsvo
Copy link

Tarpsvo commented Feb 28, 2020

Problem or feature description:

React 16.13 throws the error "Cannot update a component from inside the function body of a different component." when trying to setState() a value from onUpdate callback.

Steps to reproduce (for problems):

Snippet of code:

const [values, setValues] = useState();
const _setValues = useCallback(setValues, []);

return (
  <Slider {...props} onUpdate={_setValues} />
);

This causes a massive spam of the following error:

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

The error is also mentioned in the 16.13 changelog.

This warning will help you find application bugs caused by unintentional state changes. In the rare case that you intentionally want to change the state of another component as a result of rendering, you can wrap the setState call into useEffect.

I pretty much have no idea how I should fix this. Any guidance would be appreciated, thanks!

Versions (for problems):

React-Compound-Slider: 2.5.0
React: 16.13

@Tarpsvo Tarpsvo changed the title [Question][16.3] Cannot update a component from inside the function body of a different component. [Question] Cannot update a component from inside the function body of a different component. Feb 28, 2020
@Hrach-H
Copy link

Hrach-H commented Mar 2, 2020

I have the same issue. Haven't found a way around yet :(

So, the devs already seem to know about this issue: #106

@sghall
Copy link
Owner

sghall commented May 6, 2020

Mercifully, the React team reverted this. Should be good on react@16.13.1 ...
facebook/react#18330

If there's any further issues open this up again.

@sghall sghall closed this as completed May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants