์ด ๊ธ์์๋ ๋ทํ๋ฆญ์ค ํด๋ก ํ๋ก์ ํธ๋ฅผ ์์ํ๊ธฐ ์ํด ํ์ํ ํ๊ฒฝ ์ค์ ๊ณผ ์ด๊ธฐ ํ์ผ ๊ตฌ์กฐ ๊ตฌ์ฑ ๋ฐฉ๋ฒ์ ๋ํด ๋ค๋ฃน๋๋ค.
1. React ํ๋ก์ ํธ ์์ฑ
๋จผ์ , React ํ๋ก์ ํธ๋ฅผ ์์ฑํด์ผ ํฉ๋๋ค. ์๋ ๋ช ๋ น์ด๋ฅผ ํตํด React ์ฑ์ ๋ง๋ค ์ ์์ต๋๋ค:
npx create-react-app netflix-clone
npx create-react-app
๋ช ๋ น์ด๋ React ๊ณต์ ํ ํ๋ฆฟ์ ๊ธฐ๋ฐ์ผ๋ก ์ ํ๋ก์ ํธ๋ฅผ ์์ฑํฉ๋๋ค.netflix-clone
์ ํ๋ก์ ํธ ํด๋ ์ด๋ฆ์ ๋๋ค. ์ํ๋ ์ด๋ฆ์ผ๋ก ๋ฐ๊ฟ ์ ์์ต๋๋ค.
์์ฑ์ด ์๋ฃ๋๋ฉด ํด๋น ๋๋ ํ ๋ฆฌ๋ก ์ด๋ํฉ๋๋ค:
cd netflix-clone
์์กด์ฑ ์ค์น ํ์ธ
React ํ๋ก์ ํธ๋ฅผ ์์ฑํ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก ํ์ํ ์์กด์ฑ๋ค์ด ํจ๊ป ์ค์น๋ฉ๋๋ค. package.json
ํ์ผ์ ์ด์ด ๋ค์ ํจํค์ง๊ฐ ํฌํจ๋์ด ์๋์ง ํ์ธํ์ธ์:
react
react-dom
react-scripts
ํ์ธ ํ, ๋ก์ปฌ ์๋ฒ๋ฅผ ์คํํด ๊ธฐ๋ณธ ํ๋ฉด์ด ์ ๋จ๋์ง ํ ์คํธํฉ๋๋ค:
npm start
์น ๋ธ๋ผ์ฐ์ ์์ http://localhost:3000
์ ์ ์ํ๋ฉด ๊ธฐ๋ณธ React ํ์ด์ง๊ฐ ํ์๋ฉ๋๋ค.
2. ํ๋ก์ ํธ ํด๋ ๊ตฌ์กฐ
ํ๋ก์ ํธ๋ฅผ ์ฒด๊ณ์ ์ผ๋ก ๊ด๋ฆฌํ๊ธฐ ์ํด ํด๋ ๊ตฌ์กฐ๋ฅผ ์ค๊ณํฉ๋๋ค. ๋ทํ๋ฆญ์ค ํด๋ก ํ๋ก์ ํธ์์๋ ์๋์ ๊ฐ์ ํด๋ ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ ์์ ์ ๋๋ค:
src/
โโโ api/ # API ํธ์ถ ๊ด๋ จ ํจ์
โโโ assets/ # ์ด๋ฏธ์ง, ์์ด์ฝ, ํฐํธ ๋ฑ ์ ์ ํ์ผ
โโโ components/ # ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ UI ์ปดํฌ๋ํธ
โโโ pages/ # ๊ฐ ํ์ด์ง ์ปดํฌ๋ํธ
โโโ styles/ # CSS ํ์ผ
โโโ utils/ # ์ ํธ๋ฆฌํฐ ํจ์
โโโ App.js # ๋ฉ์ธ ์ฑ ์ปดํฌ๋ํธ
โโโ index.js # ReactDOM ๋ ๋๋ง
ํด๋ ์์ฑ
์ ๊ตฌ์กฐ์ ๋ง์ถฐ ํด๋๋ฅผ ์์ฑํฉ๋๋ค.
mkdir src/api src/assets src/components src/pages src/styles src/utils
3. ๋ผ์ฐํฐ ์ค์น ๋ฐ ์ค์
๋ทํ๋ฆญ์ค ํด๋ก ํ๋ก์ ํธ๋ ์ฌ๋ฌ ํ์ด์ง(์: ํ, ์ธ๊ธฐ ์ํ, ๊ฒ์ ๋ฑ)๋ฅผ ํฌํจํ๋ฏ๋ก, React Router๋ฅผ ์ฌ์ฉํด ๋ผ์ฐํ ์ ์ค์ ํฉ๋๋ค.
React Router ์ค์น
npm install react-router-dom
์ค์น๊ฐ ์๋ฃ๋๋ฉด, ๊ธฐ๋ณธ์ ์ธ ๋ผ์ฐํ ์ค์ ์ ์ถ๊ฐํฉ๋๋ค:
src/index.js
์์
import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import App from "./App";
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById("root")
);
src/App.js
์์
import React from "react";
import { Routes, Route } from "react-router-dom";
const HomePage = () => <div>Home Page</div>;
const PopularPage = () => <div>Popular Page</div>;
const SearchPage = () => <div>Search Page</div>;
function App() {
return (
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/popular" element={<PopularPage />} />
<Route path="/search" element={<SearchPage />} />
</Routes>
);
}
export default App;
์ด์ ๋ธ๋ผ์ฐ์ ์์ http://localhost:3000/
, http://localhost:3000/popular
, http://localhost:3000/search
์ ์ ์ํ๋ฉด ๊ฐ ํ์ด์ง๊ฐ ๋ ๋๋ง๋๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
4. CSS ์ด๊ธฐํ ๋ฐ ๊ธ๋ก๋ฒ ์คํ์ผ
๋ทํ๋ฆญ์ค ํด๋ก ํ๋ก์ ํธ๋ ์ง๊ด์ ์ด๊ณ ๊น๋ํ UI๊ฐ ํต์ฌ์ ๋๋ค. ์ด๋ฅผ ์ํด CSS ์ด๊ธฐํ๋ฅผ ์ค์ ํฉ๋๋ค.
CSS ์ด๊ธฐํ ์ถ๊ฐ
src/styles/reset.css
ํ์ผ์ ์์ฑํ๊ณ ์๋ ๋ด์ฉ์ ์ถ๊ฐํฉ๋๋ค:
/* reset.css */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #000;
color: #fff;
}
src/index.js
์์ ์คํ์ผ ์ ์ฉ
import "./styles/reset.css";
์ด์ ๊ธฐ๋ณธ ์คํ์ผ์ด ์ด๊ธฐํ๋์ด UI๋ฅผ ์ค๊ณํ๊ธฐ ์ฝ์ต๋๋ค.
5. TMDB API ํค ์ค๋น
์ํ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํด TMDB API๋ฅผ ์ฌ์ฉํ ์์ ์ ๋๋ค. TMDB API ํค๋ฅผ ๋ฐ๊ธ๋ฐ์ ์ค๋นํ์ธ์.
TMDB API ํค ๋ฐ๊ธ
- TMDB ๊ณต์ ์น์ฌ์ดํธ์ ๊ฐ์ ํฉ๋๋ค.
- ๋ก๊ทธ์ธ ํ API ํค๋ฅผ ์์ฑํฉ๋๋ค.
- ๊ณ์ ์ค์ > API > API ํค ๊ด๋ฆฌ์์ ํ์ธ ๊ฐ๋ฅ