因为新版本的React Native中componentWillMount被贬值了,componentWillMount和componentDidMount扮演着相同的角色吗? 在我的研究中,componentWillMount是在第一个渲染之前执行的,而componentDidMount是在第一个渲染之后执行的,现在的问题是,是否有任何组件在React native的第一个渲染之前自动执行?
答案 0 :(得分:0)
您可以在第一次渲染之前使用constructor()
进行操作
UNSAFE_componentWillMount()在安装发生之前被调用。它在render()之前调用,因此在此方法中同步调用setState()不会触发额外的渲染。通常,我们建议使用constructor()代替初始化状态。