0

I am new to the react-redux. Here I have this component ..

import React from 'react';
import { Route, Redirect } from 'react-router-dom';

const PrivateRoute = ({ component: Component, path, ...rest }) => {
  return localStorage.getItem("access_token") ?
    (
      <Route
        {...rest}
        path={path}
        component={Component}
      />
    )
    :
    (
      <Redirect
        to={{
          pathname: "/login",
          state: { from: path }
        }}
      />
    )
};

export default PrivateRoute;

Now, In this I want to call an api before rendering this component but we can not call this api in did mount as it is a functional component. So, Hooks are there and there is library as well.

So,How can I make this component as a class component ? and call that api.

ganesh kaspate
  • 1
  • 9
  • 41
  • 88
  • 1
    Yes I know this is question on the stack already. Only thing is then How do I make this privateComponent as a class based – ganesh kaspate Jan 24 '19 at 09:42
  • This page from the docs might be helpful: https://reactjs.org/docs/state-and-lifecycle.html#converting-a-function-to-a-class – Arnelle Balane Jan 24 '19 at 09:43

0 Answers0