最近在学习Redux,其中的Example里面大量使用了ES6语法但是我在ReactNative工程中使用使用同样的ES6语法就会报错//varReact=require('react-native');importReactfrom'react-native';syntaxError:Unexpecteduseofreservedword'import'查了一些资料,貌似需要react+webpack+babel才可以使用ES6但是不知道如何才能把这几个结合起来=======================================解决方法:React工程需要webpack+babelReact-Native工程只需要在项目根目录放一个babel配置文件.babelrc即可//.babelrc内容{"retainLines":true,"compact":true,"comments":false,"whitelist":["es6.arrowFunctions","es6.blockScoping","es6.classes","es6.destructuring","es6.parameters","es6.properties.computed","es6.properties.shorthand","es6.spread","es6.modules","es6.templateLiterals","es7.trailingFunctionCommas","es7.objectRestSpread","es7.asyncFunctions","es7.classProperties","regenerator","flow","react","react.displayName"],"sourceMaps":false}=======================================PS:不过仍存在一些问题,不知道是为什么//okvarReact=require('react-native');var{AppRegistry,Component,PropTypes}=React;//无效importReact,{AppRegistry,Component,PropTypes}from'react-native';//okvar{Provider}=require('react-redux/native');//无效import{Provider}from'react-redux';
2 回答
繁星淼淼
TA贡献1775条经验 获得超11个赞
HowtoWriteReactinES6这是我在学习Reflux的时候总结的simple-todo-with-react-and这个repo是我分别用了fluxreflux和redux实现的todo,里面都是用了ES6的语法,希望会有帮助 :)
添加回答
举报
0/150
提交
取消