-
+
+
+
+ Best
-
{title}
-
{updatedAt}
+
{article.title}
+
+ {article.image ? (
+
+ ) : undefined}
+
+
+
+
{article.writer.nickname}
-
- {likeCount}
+
+ {article.likeCount}
+
{date}
);
diff --git a/src/hooks/useMedia.ts b/src/hooks/useMedia.ts
new file mode 100644
index 00000000..2d7b3459
--- /dev/null
+++ b/src/hooks/useMedia.ts
@@ -0,0 +1,7 @@
+import { useContext } from "react";
+import { MediaContext } from "@/store/MediaContext";
+
+export function useMedia() {
+ const media = useContext(MediaContext);
+ return media;
+}
diff --git a/src/hooks/useMediaQuery.ts b/src/hooks/useMediaQuery.ts
deleted file mode 100644
index 38c9205c..00000000
--- a/src/hooks/useMediaQuery.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { useState, useEffect } from "react";
-
-export type MediaType = "PC" | "TABLET" | "MOBILE";
-
-function checkMedia(width: number): MediaType {
- if (width >= 1200) return "PC";
- if (width >= 768) return "TABLET";
- return "MOBILE";
-}
-
-export function useMediaQuery() {
- const [media, setMedia] = useState
("PC");
-
- useEffect(() => {
- setMedia(checkMedia(window.innerWidth));
-
- const handleWindowResize = () => {
- setMedia(checkMedia(window.innerWidth));
- };
-
- window.addEventListener("resize", handleWindowResize);
- return () => {
- window.removeEventListener("resize", handleWindowResize);
- };
- }, []);
-
- return media;
-}
diff --git a/src/hooks/useQuery.ts b/src/hooks/useQuery.ts
index d506cdd1..85ec8730 100644
--- a/src/hooks/useQuery.ts
+++ b/src/hooks/useQuery.ts
@@ -1,14 +1,13 @@
-import { useState, useCallback, useEffect } from "react";
+import { useState, useCallback } from "react";
export function useQuery(
- fetchFunc: (paramObj: Params) => Promise,
- paramObj: Params
+ fetchFunc: (paramObj: Params) => Promise
) {
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);
const [data, setData] = useState(null);
- const wrappedFunc = useCallback(
+ const query = useCallback(
async (paramObj: Params) => {
try {
setIsLoading(true);
@@ -27,11 +26,5 @@ export function useQuery(
[fetchFunc]
);
- const update = () => wrappedFunc(paramObj);
-
- useEffect(() => {
- wrappedFunc(paramObj);
- }, [wrappedFunc, paramObj]);
-
- return { isLoading, error, data, update };
+ return { isLoading, error, data, query };
}
diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx
index f0671c05..6b3d2cd6 100644
--- a/src/pages/_app.tsx
+++ b/src/pages/_app.tsx
@@ -1,6 +1,7 @@
import type { AppProps } from "next/app";
import localFont from "next/font/local";
import Head from "next/head";
+import { MediaProvider } from "@/store/MediaContext";
import Layout from "@/components/layout/Layout";
import "@/styles/reset.css";
import "@/styles/variable.css";
@@ -23,13 +24,15 @@ export default function App({ Component, pageProps }: MyAppProps) {
- {Component.isNotLayout ? (
-
- ) : (
-
+
+ {Component.isNotLayout ? (
-
- )}
+ ) : (
+
+
+
+ )}
+
>
);
}
diff --git a/src/store/MediaContext.tsx b/src/store/MediaContext.tsx
new file mode 100644
index 00000000..f27717d2
--- /dev/null
+++ b/src/store/MediaContext.tsx
@@ -0,0 +1,36 @@
+import { createContext, useState, useEffect, ReactNode } from "react";
+
+export type MediaType = "PC" | "TABLET" | "MOBILE";
+
+export const MediaContext = createContext(undefined);
+
+interface MediaProviderProps {
+ children: ReactNode;
+}
+
+export function MediaProvider({ children }: MediaProviderProps) {
+ const [media, setMedia] = useState();
+
+ useEffect(() => {
+ const checkMedia = (width: number): MediaType => {
+ if (width >= 1200) return "PC";
+ if (width >= 768) return "TABLET";
+ return "MOBILE";
+ };
+
+ const handleWindowResize = () => {
+ setMedia(checkMedia(window.innerWidth));
+ };
+
+ handleWindowResize();
+
+ window.addEventListener("resize", handleWindowResize);
+ return () => {
+ window.removeEventListener("resize", handleWindowResize);
+ };
+ }, []);
+
+ return (
+ {children}
+ );
+}
diff --git a/src/styles/variable.css b/src/styles/variable.css
index 5da0cdb9..78c29188 100644
--- a/src/styles/variable.css
+++ b/src/styles/variable.css
@@ -44,4 +44,7 @@
--line-md: 24px;
--line-sm: 22px;
--line-xs: 18px;
+
+ /* Font - Weight */
+ --semibold: 600;
}