脚本宝典收集整理的这篇文章主要介绍了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.
以上是脚本宝典为你收集整理的RN 0.26 引用方式中哪些属于React,哪些属于React Native全部内容,希望文章能够帮你解决RN 0.26 引用方式中哪些属于React,哪些属于React Native所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。