Why does ESlint airbnb not recommend changing setState? in the componentDidMount lifecycle function of react

I need to get the true height of the element to do something, and the most direct thing to do is certainly to get the height in componentDidMount and render it further. But the eslint I use gives a hint that it is not recommended to change setState, in the componentDidMount lifecycle function of react. Excuse me, why? If I don"t use this approach, how can I achieve my need to get the true height of the element?

clipboard.png

Mar.10,2021

in rules of eslintrc, change 'no-did-mount-set-state' to 0 .
this rule is airbnb, probably because it is worried about introducing and changing the endless cycle.


Resources

Updating the state after a component mount will trigger a second render () call and can lead to property/layout thrashing.

no-did-mount-set-state

Menu