加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 03:33:46 所属栏目:百科 来源:网络整理
导读:以前引用方式,在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 sta

以前引用方式,在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读