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.