[英]Error while using “context” in my react-es6 project
I am trying to use "context" in my es6 react code but while bundling I'm getting this error 我正在尝试在es6 react代码中使用“上下文”,但是在捆绑时却出现此错误
export default class Layout extends React.Component {
static contextTypes = {
LayoutURL : React.PropTypes.string
};
constructor(props, context) {
super(props, context);
this.state = {
}
}
}
"Module build failed: TypeError: _jsTokens2.default.matchToToken is not a function"
“模块构建失败:TypeError:_jsTokens2.default.matchToToken不是函数”
PFB my webpack code( I have added es6 in resolve but still the err is persisting) my webpack version is "^1.13.0" PFB我的webpack代码(我在解析中添加了es6,但仍然存在err)我的webpack版本是“ ^ 1.13.0”
module.exports = {
entry: './main.js',
output: { path: __dirname, filename: 'bundle.js' },
devServer: {
inline: true,
port: 8085
},
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react']
}
}
]
},
resolve: {
extensions: ['', '.js', '.jsx','.es6']
},
};
I found out that err was due to the syntax. 我发现err是由于语法引起的。 The updated syntax:
更新后的语法:
export default class Layout extends React.Component {
constructor(props, context) {
super(props, context);
this.state = { //state initialization }
}
}
Layout.contextTypes={
LayoutURL : React.PropTypes.string
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.