[英]How to fix eslint errors when using React context (consumer-provider)?
I'm using React Context API with ESLint enabled and having some issues fixing ESLint issues. 我正在使用React Context API并启用了ESLint,并且在修复ESLint问题时遇到了一些问题。
Provider: 提供者:
return (
<AuthorizationContext.Provider
value={{ isAuthorized: this.state.isAuthorized }}
>
{this.props.children}
</AuthorizationContext.Provider>
Problem: ESLint reports Parsing error: Unexpected token .
问题: ESLint报告Parsing error: Unexpected token .
for <AuthorizationContext.Provider>
for <AuthorizationContext.Provider>
Consumer: 消费者:
<AuthorizationConsumer>
{({ isAuthorized}) => {
return (
// some code here
)
}}
</AuthorizationConsumer>
Problem: ESLint reports Parsing error: Unexpected token {
for {({ isAuthorized}) => {
问题: ESLint报告Parsing error: Unexpected token {
for {({ isAuthorized}) => {
With your configuration, I have no error: https://codesandbox.io/s/j2km74l0y9 使用您的配置,我没有错误: https : //codesandbox.io/s/j2km74l0y9
But I get the same error when <AuthorizationContext.Provider>
is not inside a function, or when the code is not valid. 但是当<AuthorizationContext.Provider>
不在函数内部或代码无效时,我得到相同的错误。 Maybe check your component. 也许检查你的组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.