博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
RN 0.26 引用方式中哪些属于React,哪些属于React Native
阅读量:6464 次
发布时间:2019-06-23

本文共 1648 字,大约阅读时间需要 5 分钟。

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

转载地址:http://zjezo.baihongyu.com/

你可能感兴趣的文章