I know that it is an anti-pattern to set state on componentDidMount
and a state should be set on componentWillMount
but suppose I want to set the length of the number of li
tags as a state. In that case, I can't set the state on componentWillMount
since the li
tags might not have been mounted during that phase. So, what should be the best option here? Will it be fine if I set the state on componentDidMount
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…