繁体   English   中英

如何在使用React上下文(消费者提供者)时修复eslint错误?

[英]How to fix eslint errors when using React context (consumer-provider)?

我正在使用React Context API并启用了ESLint,并且在修复ESLint问题时遇到了一些问题。

提供者:

 return (
      <AuthorizationContext.Provider
        value={{ isAuthorized: this.state.isAuthorized }}
      >
        {this.props.children}
      </AuthorizationContext.Provider>

问题: ESLint报告Parsing error: Unexpected token . for <AuthorizationContext.Provider>

消费者:

 <AuthorizationConsumer>
        {({ isAuthorized}) => {
          return (
             // some code here
          )
        }}
      </AuthorizationConsumer>

问题: ESLint报告Parsing error: Unexpected token { for {({ isAuthorized}) => {

ESLint配置

使用您的配置,我没有错误: https//codesandbox.io/s/j2km74l0y9

但是当<AuthorizationContext.Provider>不在函数内部或代码无效时,我得到相同的错误。 也许检查你的组件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM