貌似只支持部分ES6写法?
下面这两种写法都支持
var EmbedModal = React.createClass({
componentWillMount: function() { … },
});
class EmbedModal extends React.Component {
constructor(props) {
super(props);
// Operations usually carried out in componentWillMount go here
}
}
但是下面的就只支持第一种import会报错
// ok
var React = require('react-native');
// 报错
import React from 'react-native';
而在Redux2种有都可以使用,这是什么情况呢?
https://facebook.github.io/react-native/docs/javascript-environment.html#content
官方文档里面写的很清楚,对照着看一下,哪些是支持的。
http://react-native.cn/docs/javascript-environment.html#content
官方文档里介绍了默认使用的转换器。你还可以通过编写.babelrc配置更多的plugin/preset来添加你想要的转换器。
RN内部有babel,是可以支持的
在nodemodules的react native包里面有一个packager文件夹里面有个transform.js里面定义了babel转换rn代码时的配置,默认已经支持箭头函数等es6语法,若要支持es6module等特性,可以在项目根目录下建立.babelrc文件写入babel相关配置。就是这样瞄。