RN 0.26 引用方式中哪些属于React,哪些属于React Native

以前引用方式,在0.26+版本将会报错
import React,{ Component,View } from 'react-native';

现在
import React,{ Component } from 'react';
import { View } from 'react-native';

英文原文如下

-- React Package Changes --
In React 0.14 for Web we started splitting up the React package into two packages react and react-dom. Now I'd like to make this consistent in React Native. The new package structure would be...
"react":
Children
Component
PropTypes
createElement
cloneElement
isValidElement
createClass
createFactory
createMixin
"react-native":
hasReactNativeInitialized
findNodeHandle
render
unmountComponentAtNode
unmountComponentAtNodeAndRemoveContainer
unstable_batchedUpdates
View
Text
ListView
...
and all the other native components.
So for a lot of components you actually have to import both packages.
var React = require('react');
var { View } = require('react-native');
var Foo = React.createClass({
render() { return <View />; }
});
However,for components that doesn't kNow anything about their rendering environment just need the react package as a dependency.Currently a lot of these are accessible from both packages but we'd start issuing warnings if you use the wrong one.This would be a little spammy so ideally we would have a simple codemod script that you can run on your imports to clean them up.E.g. something that translates existing patterns like:var React = require('react-native');var { View } = React;into:var React = require('react');var { View } = require('react-native');If anyone wants to write and share that script with the community,that would be highly appreciated. We can start promoting it right Now before we deprecate it.

相关文章

react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...
react 本身提供了克隆组件的方法,但是平时开发中可能很少使...
mobx 是一个简单可扩展的状态管理库,中文官网链接。小编在接...
我们在平常的开发中不可避免的会有很多列表渲染逻辑,在 pc ...