简体   繁体   English

在我的react-es6项目中使用“上下文”时出错

[英]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.

相关问题 使用 React-Context 时对象不可迭代错误 - Object is not iterable Error while Using React-Context 在Express项目中使用ES6 /标签时的语法错误/转换错误 - Syntax error / transformation error while using ES6 / tags in Express project 使用ES6时出现未知的提供程序错误 - Unknown provider error while using ES6 使用 ES6 模块导入时 GraalVM 上下文中的错误 - Error in GraalVM Context when using ES6 module imports 在业力中使用ES6时出错 - Getting error while using ES6 in karma 在反应项目中使用 db.collection() 时出错 - Error while using db.collection() in react project 使用反应测试库测试我的组件时出现此错误 - Getting this error while testing my component using react testing library 使用 React Context API 时出错:“TypeError:Object 不可迭代(无法读取属性 Symbol(Symbol.iterator))” - Error while using React Context API: "TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator))" 错误:找不到 react-redux 上下文值; 请确保组件被包裹在一个<Provider>在使用 useselector 时 - Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider> while using useselector 如何使用babel编译用es6编写的我的React文件? - how to compile my react file written in es6 using babel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM