[Question] Cannot update a component from inside the function body of a different component.
Closed this issue · 2 comments
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
I have the same issue. Haven't found a way around yet :(
So, the devs already seem to know about this issue: #106
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.