【发布时间】:2018-08-18 18:20:36
【问题描述】:
我使用 react native 最新版本的 0.54.0 并且每当在 iOS 上运行应用程序时,都会发现有关弃用生命周期方法的警告。并请更新组件。
警告:
componentWillMount 已弃用,将在下一个主要版本中删除。请改用 componentDidMount。作为临时解决方法,您可以重命名为 UNSAFE_componentWillMount。 请更新以下组件:Container、Text、TouchableOpacity、Transitioner、View
我也有根据waring添加前缀UNSAFE_的方法更改每个方法。
UNSAFE_componentDidMount() {
}
UNSAFE_componentWillMount() {
}
UNSAFE_componentWillUpdate(nextProps, nextState) {
}
UNSAFE_componentWillReceiveProps(nextProps) {
}
虽然警告还在继续。请帮帮我。
目前我已经在我的应用程序中隐藏了 YellowBox 警告。
import { YellowBox } from 'react-native';
render() {
YellowBox.ignoreWarnings([
'Warning: componentWillMount is deprecated',
'Warning: componentWillReceiveProps is deprecated',
]);
}
【问题讨论】:
-
我也在我的 SSR 网络应用程序中使用
componentWillMount...似乎有关于添加componentWillServerRender的讨论(可能会被命名为其他名称)github.com/reactjs/rfcs/pull/8/files/… 所以另一种选择可能是否要推迟升级,直到尘埃落定,然后换成新的挂钩? (如果他们被添加......如果没有。我猜又恐慌了)
标签: react-native react-native-android react-native-ios