create-react-native-app显示新警告
使用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,View Learn more about this warning here: xxx:/fb.me/react-async-component-lifecycle-hooks - node_modulesreact-nativeLibrariesReactNativeYellowBox.js:82:15 in warn - node_modulesreact-nativeLibrariesRendererReactNativeRenderer- 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_modulesreact-nativeLibrariesReactNativeYellowBox.js:82:15 in warn - node_modulesreact-nativeLibrariesRendererReactNativeRenderer- dev.js:5706:19 in printWarning - ... 21 more stack frames from framework internals 解决方法
自从我使用react-native之后已经有一段时间了,但我每天都在使用React.
您可能正在体验与新的Context API有关的事情.你应该读这个:https://github.com/facebook/react-native/issues/18175 基本上,componentWillMount将被弃用,可能在接下来的一年左右,之后,它将消失.相反,您应该能够将所有componentWillMount生命周期方法更改为componentDidMount. 要清楚,这: componentWillMount() { performTask() } 变为: componentDidMount() { performTask() } 差异主要在于调用生命周期方法的时间.值得注意的是,这些都只是功能,没有什么超级神奇的. 当组件即将开始安装时,componentWillMount()会运行,而且如果你在那里执行类似网络请求的事情(这是一种反模式),那么你可能会在组件拥有之前获得网络响应.已安装,因此无法使用数据正确设置组件的状态. componentDidMount()在安装Component和DOM时运行. 我猜这种弃用至少在某种程度上与帮助人们在组件安装时避免状态问题有关.其余的弃用可能是由于新的Context API. 你可以在这里阅读:https://reactjs.org/docs/context.html 为您提供有关这些更改的“上下文”的最快方法是,它旨在改善Redux Provider等传递数据,如果您还记得: <Provider store={store}> <App /> </Provider> 注意那里的商店.有些变化与商店有关,最终可能会弃用Redux.如果您有兴趣,我建议您进一步研究. 另外需要提及的是,与异步渲染有关的重大变化将会发生,这将极大地影响渲染性能,尤其是在大型复杂应用程序中. 要了解一切,请观看Dan Abramov撰写的这个视频: 再次注意,React 16.3 与此同时,您可能可以降级到React 16.2并恢复您认为正常的,但我猜测. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |