text: import { useState, useEffect } from "react";
  import { Redirect } from "react-router-dom";
  import firebase from "firebase/app";
  import Loader from "./components/Loader";
  
  export default function PrivateRoute(props) {
    const Component = props.component;
    const [loading, setLoading] = useState(true);
    const [user, setUser] = useState(null);
  
    useEffect(() => {
      firebase.auth().onAuthStateChanged((currentUser) => {
        if (currentUser) {
          setUser(currentUser);
        }
        setLoading(false);
      });
    }, []);
  
    return (
      <>
        {loading ? (
          <Loader />
        ) : user ? (
          <Component />
        ) : (
          <Redirect to={{ pathname: "/" }} />
        )}
      </>
    );
  }
  