使用create-react-native-app创建新的应用程序现在会生成新的警告。我需要做些什么来纠正警告吗?例如,如何更新列出的组件:
ExpoRootComponent, RootErrorBoundary, Text, View以下是新的警告:(所有这些都可以忽略吗?create-react-native-app是否会更新为使用0.55.x?)
14:30:04: Warning: componentWillMount is deprecated and will be removed in
the next major version. Use componentDidMount instead. As a temporary
workaround, you can rename to UNSAFE_componentWillMount.
Please update the following components: ExpoRootComponent,
RootErrorBoundary, Text, View
Learn more about this warning here:
xxx:/fb.me/react-async-component-lifecycle-hooks
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:82:15 in warn
- node_modules\react-native\Libraries\Renderer\ReactNativeRenderer-
dev.js:5706:19 in printWarning
- ... 21 more stack frames from framework internals
14:30:06: Warning: componentWillReceiveProps is deprecated and will be
removed in the next major version. Use static getDerivedStateFromProps
instead.
Please update the following components: Text, View
Learn more about this warning here:
xxx:/fb.me/react-async-component-lifecycle-hooks
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:82:15 in warn
- node_modules\react-native\Libraries\Renderer\ReactNativeRenderer-
dev.js:5706:19 in printWarning
- ... 21 more stack frames from framework internals发布于 2018-04-14 02:52:10
我使用react-native已经有一段时间了,但我每天都在使用React。
您可能正在经历一些与新的上下文API有关的事情。您应该阅读以下内容:https://github.com/facebook/react-native/issues/18175
基本上,componentWillMount将被弃用,可能在明年左右,在那之后,它将消失。相反,您应该能够将所有componentWillMount生命周期方法更改为componentDidMount。
需要明确的是,这是:
componentWillMount() {
performTask()
}变成:
componentDidMount() {
performTask()
}区别主要在于调用生命周期方法时的。值得注意的是,这两个都只是函数,没有什么特别神奇的地方。
componentWillMount()在组件即将开始挂载时运行,古老的风险在于,如果您在其中执行诸如网络请求之类的操作(这是一种反模式),您可能会在组件挂载之前获得网络响应,因此它将无法使用数据正确设置组件的状态。
当组件在DOM中挂载时,componentDidMount()就会运行。
我猜测,这种弃用至少在某种程度上与帮助人们在组件安装时避免状态问题有关。其余的不推荐使用可能是由于新的上下文API。
你可以在这里阅读到:https://reactjs.org/docs/context.html
给你这些变化的“上下文”的最快方法是它的目标是改善像Redux Provider这样的数据传递,如果你还记得这一点的话:
<Provider store={store}>
<App />
</Provider>注意那里的商店。与存储相关的更改即将到来,最终可能会弃用Redux。如果你感兴趣,我建议你进一步研究它。
另一件值得一提的是,异步渲染带来了严重而重大的变化,这将极大地影响渲染性能,特别是在大型、复杂的应用程序中。
要了解一切,请观看丹·阿布拉莫夫的视频:https://www.youtube.com/watch?v=v6iR3Zk4oDY
再次注意,React 16.3+
在此期间,你也许能够降级回到反应16.2,并恢复你认为是正常的,但我在猜测。
发布于 2018-04-16 15:24:22
可以安全地忽略这些警告,但从react 17.x开始,不推荐使用的生命周期方法将不再存在。
如果你想更新,this SO post真的很有帮助。这是我上周用来更新我的代码库的代码。这两个问题的答案都提供了关于如何更新代码的内部信息,这取决于您在生命周期钩子中做了什么。
注意:许多npm库也使用过时的生命周期警告,并且它们中的许多还不是最新的API更改。因此,即使您从代码中删除了所有不推荐使用的方法,您仍有可能在控制台中看到警告。
https://stackoverflow.com/questions/49823294
复制相似问题