์ปดํฌ๋ํธ๊ฐ ๋ง์์ง๋ฉด ๋ ์ด ์ปดํฌ๋ํธ๋ค์ ๋ถ๋ฆฌํด์ค ํ์๊ฐ ์๋ค.
๊ทธ๋ฆฌ๊ณ App.js์ ํ์ผ์ ์์ด์ ๋ค๋ฅธ ํ์ผ์์ ์ด ํ์ผ ์์ ์ปดํฌ๋ํธ๋ค์ ๊ฐ์ ธ๋ค๊ฐ ์ฐ๊ธฐ ์ด๋ ต๋ค.
๊ฐ๊ฐ ์ปดํฌ๋ํธ ๋ณ๋ก ํ์ผ๋ก ์ชผ๊ฐ ๋ณผ ๊ฒ์ด๋ค.
์ฐ์ src ๋๋ ํฐ๋ฆฌ์ components ๋ผ๋ ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ง๋ค ๊ฒ์ด๋ค.
์ด ๋๋ ํฐ๋ฆฌ ์์ ๊ฐ๊ฐ์ ์ปดํฌ๋ํธ ๋ณ๋ก ํ์ผ์ ๋ง๋ค์ด ์ค ๊ฒ์ด๋ค.
create-react-app์ด ๊ธฐ๋ณธ์ ์ผ๋ก index.js๋ฅผ ๋ณด๋ฉด
App์ด๋ผ๋ ์ปดํฌ๋ํธ๋ฅผ ๊ฐ์ ๋๋ ํฐ๋ฆฌ์ ์๋ App.js๋ผ๋ ํ์ผ์์ importํด์ ์ฐ๊ณ ์๋ ๊ฒ์ด๋ค.
components ๋๋ ํฐ๋ฆฌ์ TOC.js ํ์ผ์ ๋ง๋ค๊ณ TOC ์ปดํฌ๋ํธ๋ฅผ ๋ณต๋ถํ๋ค
(์ฌ๊ธฐ์ ๊ฐ ์๋ํฐ์ ๋ฐ๋ผ์ ์ปดํฌ๋ํธ๋ฅผ ํด๋์ค๊ฐ ์ฌ์ฉ๋๊ณ ์๋๋ฐ ์ด๊ฒ์ ๋ก๋ฉํ๋ ์ฝ๋๊ฐ ์๋ค๊ณ ํ๋ฉด์ ๋นจ๊ฐ์ค์ด ๋ฐ ์ ๋ ์๋ค.)
๊ทธ ๋ค์์ TOC๋ผ๋ ํ์ผ ์์ ์ฌ๋ฌ๊ฐ์ง ๋ณ์, ํจ์๊ฐ ์กด์ฌํ ์ ์๋ค.
์ด ์ค์์ ์ธ๋ถ์์ ์ฌ์ฉํ ์ ์๊ฒ ํ๋ ๊ฒ์ด export ์ด๋ค. ์ฆ, TOC๋ผ๋ ํด๋์ค๋ฅผ ์ธ๋ถ์์ ์ธ ์ ์๋ ๊ฒ์ด๋ค.
์ด๋ ๊ฒ ์ปดํฌ๋ํธ๋ฅผ ๋ถ๋ฆฌํด์ฃผ์์ผ๋ App.js ํ์ผ์์๋ TOC ํด๋์ค๋ฅผ ์ง์์ฃผ๊ณ
TOC ํ์ผ์ import ํด์ค๋ค.
import TOC from "./components/TOC"
๋๋จธ์ง ์ปดํฌ๋ํธ๋ ๋ถ๋ฆฌํด์ฃผ์๋ค.
๐ฝ App.js
import './App.css';
import React, { Component } from 'react';
import TOC from "./components/TOC"
import Content from "./components/Content"
import Subject from "./components/Subject"
// ์ปดํฌ๋ํธ๋ฅผ ๋ง๋๋ ์ฝ๋ (ํ
ํ๋ฆฟ)
// ๋ฆฌ์กํธ์ Component๋ผ๊ณ ํ๋ ํด๋์ค๋ฅผ ์์ํ๋
// App ์ด๋ผ๋ ํด๋์ค - render()๋ผ๋ ํจ์๋ฅผ ๊ฐ์ง๊ณ ์๋ค.
class App extends Component {
render(){
return (
<div className="App">
<Subject title="WEB" sub="world wide web!"></Subject>
<Subject title="React" sub="for UI"></Subject>
<TOC></TOC>
<Content title="HTML" desc="HTML is HyperText Markup Language."></Content>
</div>
);
}
}
export default App;
'WEB > Front-End๐' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[React] event (0) | 2021.10.04 |
---|---|
[React] state๋? (props์ ๋น๊ต) (0) | 2021.10.02 |
[React] Props (0) | 2021.10.01 |
[React] ์ปดํฌ๋ํธ ๋ง๋ค๊ธฐ (๊ธฐ์ดํํ) (0) | 2021.09.28 |
[React] ๋ฆฌ์กํธ์์ CSS ์์ + Deploy(๋ฐฐํฌ) ํ๊ธฐ (0) | 2021.09.28 |