create-react-native-app 显示新警告

DCR*_*DCR 5 react-native create-react-native-app

使用 create-react-native-app 创建新应用程序现在会生成新警告。我需要做些什么来纠正警告?例如,我将如何更新列出的组件:

 ExpoRootComponent, RootErrorBoundary, Text, View
Run Code Online (Sandbox Code Playgroud)

这是新的警告:(所有这些都可以忽略吗?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
Run Code Online (Sandbox Code Playgroud)

agm*_*984 1

已经有一段时间没有使用react-native了,但是我每天都在使用React。

您可能正在经历一些与新的 Context API 有关的事情。您应该阅读此内容:https ://github.com/facebook/react-native/issues/18175

基本上,componentWillMount可能会在明年左右被弃用,之后就会消失。相反,您应该能够将所有componentWillMount生命周期方法更改为componentDidMount.

需要明确的是,这个:

componentWillMount() {
  performTask()
}
Run Code Online (Sandbox Code Playgroud)

变成:

componentDidMount() {
  performTask()
}
Run Code Online (Sandbox Code Playgroud)

区别主要在于生命周期方法何时被调用。值得注意的是,这些都只是函数,没有什么特别神奇的地方。

componentWillMount()当组件即将开始安装时运行,古老的风险是,如果您在其中执行类似网络请求的操作(这是一种反模式),您可能会在组件安装之前收到网络响应,因此例如,它将无法使用数据正确设置组件的状态。

componentDidMount()当组件被安装并在 DOM 中时运行。

我猜想这种弃用至少在某种程度上与帮助人们避免安装组件时的状态问题有关。其余的弃用可能是由于新的 Context API。

您可以在这里阅读: https: //reactjs.org/docs/context.html

为您提供有关这些更改的“上下文”的最快方法是,它旨在改进 Redux Provider 等数据传递,如果您还记得这一点:

<Provider store={store}>
  <App />
</Provider>
Run Code Online (Sandbox Code Playgroud)

注意那里的商店。与商店相关的变化即将到来,最终可能会弃用 Redux。如果您有兴趣,我建议您进一步研究。

另一件值得一提的是,即将发生与异步渲染有关的严重且重大的变化,这将极大地影响渲染性能,特别是在大型复杂的应用程序中。

要了解所有内容,请观看 Dan Abramov 的视频: https://www.youtube.com/watch ?v=v6iR3Zk4oDY

再次注意,React 16.3+

与此同时,您也许可以降级回 React 16.2 并恢复您认为正常的状态,但我只是猜测。