[์ถ์ฒ : Youtube - ์ํ์ฝ๋ฉ]
https://youtu.be/8hGqznPGVc0?list=PLuHgQVnccGMCRv6f8H9K5Xwsdyg4sFSdi
src ๋๋ ํ ๋ฆฌ ์์ components ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํ๋ค.
components ๋๋ ํ ๋ฆฌ ์์๋ TOC.js๋ผ๋ ํ์ผ์ ์์ฑํ๋ค.
TOC.js ํ์ผ์๋ค๊ฐ App.js์ TOC ํด๋์ค๋ฅผ ๋ณต๋ถํ๋ค.
์๋์ ์ฝ๋๋ ๊ฐ์ด ๋ณต๋ถํ๋ค.
import React, { Component } from 'react';
'react๋ผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ Component๋ผ๊ณ ํ๋ ํด๋์ค๋ฅผ ๋ก๋ฉํ๋ค' ๋ผ๋ ๋ป์ด๋ค.
๋ฆฌ์กํธ๋ฅผ ์ฌ์ฉํ ๋ ํ์์ ์ผ๋ก ๋ฃ์ด์ผํ๋ ์ฝ๋๋ผ๊ณ ์๊ฐํ๋ฉด ๋๋ค.
TOC๋ผ๋ ํด๋์ค๋ฅผ ์ธ๋ถ์์ ์ฌ์ฉํ ๊ฒ์ ํ์ฉํ๋ ์ฝ๋๋ ์์ฑํ๋ค.
export default TOC;
์๋์ ์ฝ๋๋ฅผ ์์ฑํ๊ณ App.js ๋ด์ TOC ํด๋์ค๋ ์ญ์ ํ๋ค.
import TOC from "./components/TOC";
src/App.js
import './App.css';
import TOC from "./components/TOC";
import React, { Component } from 'react';
class Subject extends Component {
render() {
return (
<header>
<h1>{this.props.title}</h1>
{this.props.sub}
</header>
);
}
}
class Content extends Component {
render() {
return (
<article>
<h2>{this.props.title}</h2>
{this.props.desc}
</article>
);
}
}
class App extends Component {
render() {
return (
<div className="App">
<Subject title="WEB" sub="world wide web!"></Subject>
<TOC></TOC>
<Content title="HTML" desc="HTML is HyperText Markup Language."></Content>
</div>
);
}
}
export default App;
๋ค๋ฅธ ํด๋์ค๋ค๋ ๋๊ฐ์ด ํด์ค๋ค.
์ด๋ ๊ฒ ํ๋ฉด ์ฝ๋๊ฐ ํจ์ฌ ๊ฐ๊ฒฐํด์ง๋ค.
src/App.js (์ฝ๋ ๋ถ๋ฆฌ ํ)
import './App.css';
import TOC from "./components/TOC";
import Content from "./components/Content";
import Subject from "./components/Subject";
import React, { Component } from 'react';
class App extends Component {
render() {
return (
<div className="App">
<Subject title="WEB" sub="world wide web!"></Subject>
<TOC></TOC>
<Content title="HTML" desc="HTML is HyperText Markup Language."></Content>
</div>
);
}
}
export default App;
'JavaScript > React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Custom-Hook (0) | 2021.11.16 |
---|---|
[์ํ์ฝ๋ฉ-React] State ์ฌ์ฉ (0) | 2021.05.29 |
[์ํ์ฝ๋ฉ-React] props (0) | 2021.05.29 |
[์ํ์ฝ๋ฉ-React] ์ปดํฌ๋ํธ ๋ง๋ค๊ธฐ 2 (0) | 2021.05.28 |
[์ํ์ฝ๋ฉ-React] ์ปดํฌ๋ํธ ๋ง๋ค๊ธฐ 1 (0) | 2021.05.28 |
๋๊ธ