鍍金池/ 問答/HTML5  HTML/ 請問這種react組件寫法換成class的寫法應(yīng)該怎么寫?

請問這種react組件寫法換成class的寫法應(yīng)該怎么寫?

const PrivateRoute = ({ component: Component, ...rest }) => (
  <Route
    {...rest}
    render={props =>
      fakeAuth.isAuthenticated ? (
        <Component {...props} />
      ) : (
        <Redirect
          to={{
            pathname: "/login",
            state: { from: props.location }
          }}
        />
      )
    }
  />
);

(在下看不懂上面這種的寫法)
請問上面的寫法如何翻譯成 class App extends Component {...} 這種寫法?
https://reacttraining.com/react-router/web/example/auth-workflow

回答
編輯回答
放開她
class PrivateRoute extends React.Component {

    render(){
        const { component: Component, ...rest } = this.props
        
        return (
            <Route
                {...rest}
                render={props =>
                  fakeAuth.isAuthenticated ? (
                    <Component {...props} />
                  ) : (
                    <Redirect
                      to={{
                        pathname: "/login",
                        state: { from: props.location }
                      }}
                    />
                  )
                }
              />)
    }
  
}
2017年8月30日 05:47