2주차 스프린트 계획 · boostcampwm-2022/web21-devrank Wiki

백엔드

Untitled

만났던 문제

API 요청 횟수 제한 문제 발생

프론트엔드

고민한 부분들

  1. 재사용 가능한 컴포넌트 만들기

    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>
      );
    }
    
  2. 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;

Tanstack-query