2017-06-03 3 views
0

条件付きで小道具を広げる方法を理解しようとしています。以下は、私がthis.props.isAuthenticated1thisに関連する予期しないトークンを言っライン{this.props.isAuthenticated && {...this.props}}にエラーが発生します。条件付きチェックに基づくスプレッド小道

class ProtectedRoute extends Component { 
    render() { 

    const ComponentToRender = this.props.component, 
     RouteToRender = (
     <Route 
      {this.props.isAuthenticated && {...this.props}} 
      render={({Component}) => 
      (this.props.isAuthenticated ? (<ComponentToRender {...this.props} />) : 
       (<Redirect 
       to={{ 
        pathname: '/login', 
        state: {from: this.props.location 
        }}} 
       />))} 
     />) 

    return (RouteToRender) 
    } 
} 

答えて

2

はそれを行います

{...(this.props.isAuthenticated && this.props)} 

{this.props.isAuthenticated && {...this.props}} 

を変更します。

関連する問題