ํฐ์คํ ๋ฆฌ ๋ทฐ
์ด ๊ธ์ ์ํ์ฝ๋ฉ React ๊ฐ์[opentutorials.org/module/4058]๋ฅผ ์ฐธ๊ณ ํ์ฌ ์์ฑํ์์ต๋๋ค.
[Refactoring ํ๋ ๋ฒ - props ์ฌ์ฉ]
๋ฆฌํฉํ ๋ง์ด๋?
์ธ๋ถ๋์์ ๋ฐ๊พธ์ง ์์ผ๋ฉด์ ๋ด๋ถ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ ํ๋ ๋ฐฉ๋ฒ
Original <App.js>
import React, { Component } from 'react';
import './App.css';
class Subject extends Component {
render() {
return (
<header>
<h1>WEB</h1>
world wide web!
</header>
);
}
}
class App extends Component {
render() {
return (
<div className="App">
<Subject></Subject>
</div>
);
}
}
export default App;
props ์ถ๊ฐํ <App.js>
class Subject extends Component {
render() {
return (
<header>
<h1>{this.props.title}</h1>
{this.props.sub}
</header>
);
}
}
class App extends Component {
render() {
return (
<div className="App">
<Subject title="WEB" sub="world wide web"></Subject>
<Subject title="React" sub="For UI"></Subject>
</div>
);
}
}
Props ์ฌ์ฉ ๋ฒ - ๊ณต์๋ฌธ์
ko.reactjs.org/docs/components-and-props.html
[์ปดํฌ๋ํธ ํ์ผ๋ก ๋ถ๋ฆฌํ๊ธฐ]
Original <App.js>
import React, { Component } from 'react';
import './App.css';
class Subject extends Component {
render() {
return (
<header>
<h1>WEB</h1>
world wide web!
</header>
);
}
}
class TOC extends Component {
render() {
return (
<nav>
<ul>
<li><a href="1.html">HTML</a></li>
<li><a href="2.html">CSS</a></li>
<li><a href="3.html">JavaScript</a></li>
</ul>
</nav>
);
}
}
class Content extends Component {
render() {
return (
<article>
<h2>HTML</h2>
HTML is HyperText Markup Language.
</article>
);
}
}
class App extends Component {
render() {
return (
<div className="App">
<Subject></Subject>
<TOC></TOC>
<Content></Content>
</div>
);
}
}
export default App;
<TOC.js>
import React, { Component } from 'react';
class TOC extends Component {
render() {
return (
<nav>
<ul>
<li><a href="1.html">HTML</a></li>
<li><a href="2.html">CSS</a></li>
<li><a href="3.html">JavaScript</a></li>
</ul>
</nav>
);
}
}
export default TOC;
<Content.js>
import React, { Component } from 'react';
class Content extends Component {
render() {
return (
<article>
<h2>{this.props.title}</h2>
{this.props.desc}
</article>
);
}
}
export default Content;
<Subject.js>
import React, { Component } from 'react';
class Subject extends Component {
render() {
return (
<header>
<h1>{this.props.title}</h1>
{this.props.sub}
</header>
);
}
}
export default Subject;
Changed <App.js>
import React, { Component } from 'react';
import './App.css';
import TOC from "./components/TOC";
import Content from "./components/Content";
import Subject from "./components/Subject";
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;
์๋ App.js ํ์ผ์์ 3๊ฐ์ ์ปดํฌ๋ํธ๋ฅผ ๊ฐ๊ฐ TOC.js, Content.js, Subject.js ํ์ผ๋ก ๋ถ๋ฆฌํ๋ค.
App.js ํ์ผ์๋ ๊ผญ import๋ฅผ ํด์ค๋ค!
๋๊ธ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- ๋ฆฌ์กํธ setState
- ๋ฆฌ์กํธ useEffect
- machine learning
- ๋ฆฌ๋์ค store
- ๋ฆฌ์กํธ ์ปดํฌ๋ํธ
- Docker&Kubernetes:์ค์ ๊ฐ์ด๋-2022๋ ํ
- React Hook
- ๊ตฌ๊ธํด๋ผ์ฐ๋ํ๋ซํผ
- ๋ฆฌ์กํธ
- docker
- ํ ์ํ๋ก์ฐ
- ML
- React
- ๋ฆฌ์กํธ ๊ธฐ์ด
- ๋ฆฌ์กํธ ๊ณต์๋ฌธ์
- ๊ตฌ๊ธ
- Cloud
- ๋์ปค
- ์ปดํฌ๋ํธ
- ๋ฆฌ์กํธ state
- ๋จ๊ธฐ์ง์ค๊ณผ์
- ๋ฆฌ์กํธ ๋ ๋๋ง
- GCP
- ํด๋ผ์ฐ๋
- ๋จธ์ ๋ฌ๋
- ์ํ์ฝ๋ฉ ๋ฆฌ์กํธ
- ๋ฆฌ์กํธ ํ
- React DOM
- ๋ฆฌ๋์ค
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
๊ธ ๋ณด๊ดํจ