ํฐ์คํ ๋ฆฌ ๋ทฐ
์ด ๊ธ์ ์ํ์ฝ๋ฉ React ๊ฐ์[opentutorials.org/module/4058]๋ฅผ ์ฐธ๊ณ ํ์ฌ ์์ฑํ์์ต๋๋ค.
[State๋?]
- Component : ์ฌ์ฉ์๊ฐ ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉํ๋ ์ ์ฅ์์ ์ค์
- Props : ์ปดํฌ๋ํธ์ ์์ฑ, ์ฌ์ฉ์์๊ฒ ์ค์, ์ธ๋ถ
- State : props์ ๊ฐ์ ๋ฐ๋ผ ๋ด๋ถ ๊ตฌํ์ ํ์ํ ๋ฐ์ดํฐ
=> props์ state๋ฅผ ์ฒ ์ ํ ๋ถ๋ฆฌ!
[State ์ฌ์ฉ]
Original <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;
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 {
constructor(props){
super(props);
this.state = {
subject:{title:"WEB", sub:"world wide web"}
} //state๊ฐ ์ด๊ธฐํ
} //component ์์ constructor๋ ๊ฐ์ฅ ๋จผ์ ์คํ๋๋ฉฐ ์ด๊ธฐํ๋ฅผ ๋ด๋น
render() {
return (
<div className="App">
<Subject
title={this.state.subject.title}
sub ={this.state.subject.sub}>
</Subject>
<Subject title="React" sub="For UI"></Subject>
<TOC></TOC>
<Content title="HTML" desc="HTML is HyperText Markup Language."></Content>
</div>
);
}
}
export default App;
[Key ์ฌ์ฉ]
๊ฐ๊ฐ์ ํญ๋ชฉ๋ค์ key๋ผ๊ณ ํ๋ props๋ฅผ ๊ฐ์ง๊ณ ์์ด์ผํจ
<TOC.js>
import React, { Component } from 'react';
class TOC extends Component {
render() {
var lists = [];
var data = this.props.data;
var i = 0;
while(i < data.length){
lists.push(<li key={data[i].id}><a href={"/contect/"+data[i].id}>{data[i].title}</a></li>);
i = i + 1;
}
return (
<nav>
<ul>
{lists}
</ul>
</nav>
);
}
}
export default TOC;
<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 {
constructor(props){
super(props);
this.state = {
subject:{title:"WEB", sub:"world wide web"},
contents:[
{id:1, title:'HTML', desc:'HTML is for information'},
{id:2, title:'CSS', desc:'CSS is for design'},
{id:3, title:'JavaScript', desc:'JavaScript is for interactive'}
]
} //state๊ฐ ์ด๊ธฐํ
} //component ์์ constructor๋ ๊ฐ์ฅ ๋จผ์ ์คํ๋๋ฉฐ ์ด๊ธฐํ๋ฅผ ๋ด๋น
render() {
return (
<div className="App">
<Subject
title={this.state.subject.title}
sub ={this.state.subject.sub}>
</Subject>
<Subject title="React" sub="For UI"></Subject>
<TOC data={this.state.contents}></TOC>
<Content title="HTML" desc="HTML is HyperText Markup Language."></Content>
</div>
);
}
}
export default App;
๋๊ธ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- React DOM
- ๋ฆฌ์กํธ state
- ํ ์ํ๋ก์ฐ
- ๋ฆฌ์กํธ
- ์ํ์ฝ๋ฉ ๋ฆฌ์กํธ
- machine learning
- React Hook
- ๋ฆฌ์กํธ useEffect
- ML
- ๋ฆฌ์กํธ ์ปดํฌ๋ํธ
- ๊ตฌ๊ธ
- docker
- ๋จธ์ ๋ฌ๋
- ๋ฆฌ์กํธ ๊ณต์๋ฌธ์
- ๋ฆฌ๋์ค store
- ๋จ๊ธฐ์ง์ค๊ณผ์
- ๋ฆฌ์กํธ setState
- GCP
- ๋ฆฌ์กํธ ํ
- ํด๋ผ์ฐ๋
- ๋ฆฌ์กํธ ๋ ๋๋ง
- ๋ฆฌ์กํธ ๊ธฐ์ด
- React
- ๋์ปค
- ๊ตฌ๊ธํด๋ผ์ฐ๋ํ๋ซํผ
- ์ปดํฌ๋ํธ
- Docker&Kubernetes:์ค์ ๊ฐ์ด๋-2022๋ ํ
- Cloud
- ๋ฆฌ๋์ค
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
๊ธ ๋ณด๊ดํจ