2주차 스프린트 계획 · boostcampwm-2022/web21-devrank Wiki
Github Enterpise가 아니라면 1시간에 5000번으로 요청을 제한
전체 유저의 랭킹을 업데이트해야하는 경우 5000번의 요청이 너무 제한적이다
재사용 가능한 컴포넌트 만들기
function Dropdown({ trigger, children }: DropdownProps) {
const [isOpen, setIsOpen] = useState(false);
const containerRef = useRef<HTMLDivElement | null>(null);
const onClickBackground = (e: MouseEvent) => {
if (e.target instanceof HTMLElement) {
if (!containerRef.current) return;
if (!containerRef.current.contains(e.target)) {
setIsOpen(false);
}
}
};
useEffect(() => {
window.addEventListener('click', onClickBackground);
return () => window.removeEventListener('click', onClickBackground);
}, []);
return (
<Container ref={containerRef} onClick={() => setIsOpen((prev) => !prev)}>
{trigger}
{isOpen && <Options>{children}</Options>}
</Container>
);
}
Tanstack-query
function App({ Component, pageProps }: AppProps) {
const queryClient = new QueryClient();
interface AuthProviderProps {
children: React.ReactNode;
}
function AuthProvider({ children }: AuthProviderProps) {
const [auth, setAuth] = useState<AuthType>({
isLoggedIn: false,
user: {
id: '',
username: '',
avatarUrl: '',
},
});
return <AuthContext.Provider value={{ auth, setAuth }}>{children}</AuthContext.Provider>;
}
function App({ Component, pageProps }: AppProps) {
return (
<>
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={theme}>
<AuthProvider>
<GlobalStyles />
<div className={notoSansKR.className}>
<Layout>
<Component {...pageProps} />
</Layout>
</div>
</AuthProvider>
</ThemeProvider>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</>
);
}
function Callback() {
const router = useRouter();
const { setAuth } = useContext(AuthContext);
useEffect(() => {
if (!router.isReady) return;
const code = router.query.code as string;
(async function () {
try {
await requestGithubLogin(code);
router.push('/');
setAuth({
isLoggedIn: true,
});
} catch (err) {
console.error(err);
}
})();
}, [router.isReady]);
return (
<Container>
<Spinner width={60} height={60} />
</Container>
);
}
export default Callback;