2017-11-20 13 views
2

私はeslintからこの警告を受けました。私はcreate-react-appを使用しています。reduxを使用しているときにeslintのエラーが発生しました

./src/components/auth.js 
    Line 24: Unexpected labeled statement           no-labels 
    Line 24: 'authenticated:' is defined but never used        no-unused-labels 
    Line 24: Expected an assignment or function call and instead saw an expression no-unused-expressions 

そして私は、私は以下の私のコンポーネントに問題を持っていないと思うが、それは

import React, { Component } from 'react'; 
import { connect } from 'react-redux'; 

export default function(ComposedComponent) { 
    class Authentication extends Component { 

    componentWillMount() { 
     if (!this.props.authenticated) { 
     this.props.history.replace('/login'); 
     } 
    } 

    componentWillUpdate(nextProps) { 
     if (!nextProps.authenticated) { 
     this.props.history.replace('/login'); 
     } 
    } 

    render() { 
     return <ComposedComponent {...this.props} /> 
    } 
    } 

    return connect(state => {authenticated: state.auth.authenticated})(Authentication); 
} 

私はeslintを使用して固定すべきか見当もつかない、初めてきませんので、迷惑なんです。

+0

HIマデリーンあなたeslintの設定を保存するために、そのメソッドを使用している場合(あなた.eslintrcまたはpackage.jsonをご提示ください。 – Zargold

答えて

1

これを書いているときは、JavaScriptが混乱しています。

命令authenticated: state.auth.authenticatedが間違った命令であることを返す矢印関数が表示されています。


次のいずれか書くことができます:私たちは、この命令が、JSONではありませんJavaScriptを伝えるために、括弧を追加

connect(state => ({ 
    authenticated: state.auth.authenticated, 
})); 

それとも

connect((state) => { 
    return { 
    authenticated: state.auth.authenticated, 
    }; 
}); 
関連する問題