sghall / react-compound-slider

:black_medium_small_square: React Compound Slider | A small React slider with no opinion on markup or styles
https://react-compound-slider.netlify.com
MIT License
626 stars 80 forks source link

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

Closed Tarpsvo closed 4 years ago

Tarpsvo commented 4 years ago

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

Hrach-H commented 4 years ago

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

So, the devs already seem to know about this issue: https://github.com/sghall/react-compound-slider/issues/106

sghall commented 4 years ago

Mercifully, the React team reverted this. Should be good on react@16.13.1 ... https://github.com/facebook/react/pull/18330

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