import React, { useEffect, useState } from 'react';
import { dehydrate, QueryClient, useQuery } from 'react-query';
import User from '../interfaces/user';
import AppLayout from '../components/AppLayout';
import { loadMyInfoAPI } from '../apis/login';
import LoginLayout from '../components/login';
import { GetServerSidePropsContext } from 'next';
import axios, { AxiosError } from 'axios';
import Router from 'next/router';
import { Spin } from 'antd';
const Home = () => {
//const [ref, inView] = useInView();
const [loading, setLoading] = useState(true);
const { data: me } = useQuery<User>('user', loadMyInfoAPI);
useEffect(() => {
console.log('1111');
if (me) {
setLoading(false);
}
}, [me]);
return (
<div>
{loading == true ? (
<div className="loadingBar">
<Spin />
</div>
) : me ? (
<AppLayout />
) : (
<LoginLayout />
)}
</div>
);
};
export const getStaticProps = async () => {
const queryClient = new QueryClient();
await queryClient.prefetchInfiniteQuery('user', () => loadMyInfoAPI());
return {
props: {
dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))),
},
};
};