{"size": 1067, "ext": "js", "max_stars_repo_path": "frontend/src/pages/profile/index.js", "max_stars_repo_name": "IronOnet/pystagram", "max_stars_repo_stars_event_min_datetime": "2022-02-19T15:26:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-19T15:26:27.000Z", "max_issues_repo_path": "frontend/src/pages/profile/index.js", "max_issues_repo_name": "IronOnet/pystagram", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "frontend/src/pages/profile/index.js", "max_forks_repo_name": "IronOnet/pystagram", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.6388888889, "max_line_length": 63, "alphanum_fraction": 0.5435801312}
import {useParams, useNavigate} from "react"; 
import {useState, useEffect} from "react"; 
import {getUserByUsername}  from "../../services/axios"; 
import * as ROUTES from "../../constants/routes";
import Header from "../../components/header";
import UserProfile from "../../components/profile";



export default function Profile(){
    const {username } = useParams(); 
    const [user, setUser] = useState(null); 
    const navigate = useNavigate(); 

    useEffect(()=>{
        async function checkUserExists(){
            const [user] = await getUserByUsername(username); 
            if (user?.userId){
                setUser(user);
            } else{
                navigate(ROUTES.NOT_FOUND)
            }
        }
        //checkUserExists();
    }, [username, navigate]);


    return user?.username ?(
        <div className="bg-gray-background">
            <Header/>
            <div className="mx-auto max-w-screen-lg">
                <UserProfile user={user}/>
            </div>
        </div>
    ): null;
}