text: import React from 'react';
  import { useContext } from 'react';
  
  // import react router components
  import { Redirect, Route } from 'react-router-dom';
  import { UserContext } from '../../App';
  
  const PrivateRoute = ({ children, ...rest }) => {
      // consume UserContext data from App
      const [loggedInUser, setLoggedInUser] = useContext(UserContext);
  
      return (
          <Route
              {...rest}
              render={({ location }) =>
                  loggedInUser.email ? (
                      children
                  ) : (
                      <Redirect
                          to={{
                              pathname: "/login",
                              state: { from: location }
                          }}
                      />
                  )
              }
          />
      );
  };
  
  export default PrivateRoute;