ํฐ์คํ ๋ฆฌ ๋ทฐ
[React Study] ์ํ์ฝ๋ฉ React - 12. props ~ 15.3. key
๊ตฌ๋์ 2022. 3. 31. 02:53
React - 12. props
class TOC extends Component{
render(){
return(
<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>
);
}
}
- link ํ๊ทธ์๋ a๋ผ๋ ๊ฒ์ ํตํด ์ด๊ฒ์ด ํ๊ทธ๋ผ๋ ๊ฒ์ ์๋ ค์ค
- ์ด๊ฒ์ด ์ด๋ค ์ฃผ์๋ ์ฐ๊ฒฐ๋๋์ง ์๋ ค์ค ํ์๊ฐ ์์
- href="1.html" โก ํ๊ทธ์ ์์ฑ(attribute)๋ฅผ ํตํด ์ ์ ์์
<Subject title = "WEB" sub = "world wide web!"></Subject>
โก ์์ฒ๋ผ title๊ณผ sub title์ ํตํด์ ๊ตฌ๋ณํ ์ ์๋ค๋ฉด ์ผ๋ง๋ ์ข์๊น?
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>
<TOC></TOC>
<Content>z</Content>
</div>
);
}
}
- {this.props.title} ์ ํตํด ์ฝ๊ฒ ์ฌ์ฌ์ฉ ๊ฐ๋ฅ
React - 13. React Developer Tools
- React Developer Tool ํฌ๋กฌ ํ์ฅ ํ๋ก๊ทธ๋จ ์ค์น
- F12ํค๋ฅผ ๋๋ฅด๊ณ React ํญ์ ๋ค์ด๊ฐ๋ฉด ์ด๋ ๊ฒ ์ค์๊ฐ์ผ๋ก ์์ ๊ฐ๋ฅ
React - 14. Component ํ์ผ๋ก ๋ถ๋ฆฌํ๊ธฐ
- ๊ฐ๊ฐ์ ์ปดํฌ๋ํธ๋ณ๋ก ๋ณ๋์ ํ์ผ ์ ๋ฆฌ
- component ๋ผ๋ ํ์ผ์ ๋ง๋ค์ด ๋ถ๋ฅํ ์์
- TOC.js ํ์ผ ๋ง๋ฌ
import { Component } from 'react';
- ํ์ ์ฝ๋
- ๋ฆฌ์กํธ๋ผ๋ ๊ณณ์์ ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉ
export default TOC;
- ํด๋์ค๋ฅผ ๊ฐ์ ธ๋ค ์ฌ์ฉํ ์ ์๊ฒ ํด์ค
- ๊ด๋ จ ์ฝ๋๋ฅผ index.js์์ ์ง์๋ ๊ฒฐ๊ณผ๋ ๋๊ฐ์
React - 15.1. State ์๊ฐ
์ฌ์ฉ์์ ์ ์ฅ์์ ์ฅ์น๋ฅผ ์กฐ์ ํ๋ ๊ฒ๋ค โก ์ ์ ์ธํฐํ์ด์ค, ๋ฒํผ ๋ฑ๋ฑ..
์ปดํฌ๋ํธ์ ๋์์ ๋ฐ๊พธ๊ณ ์ถ์ ๋
โก props
์ปดํฌ๋ํธ ๋ด๋ถ์์ ์ฌ์ฉ๋๋ ๊ฒ๋ค์?
โก State
React - 15.2. State ์ฌ์ฉ
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>
);
}
}
- App.js์ ์ ๋ถ๋ถ ์ฝ๋๋ฅผ ์์ ํ ๊ฒ
class App extends Component {
constructor(props){
super(props)
}
- ์ฝ๋๋ฅผ ์คํํ ๋ render() ํจ์๋ณด๋ค ๋จผ์ ์คํ์ด ๋๋ฉด์ component๋ฅผ ์ด๊ธฐํ์์ผ ์ค ๋ ์ ์ฝ๋ ์ฌ์ฉ
class App extends Component {
constructor(props){
super(props)
this.state = {
subject:{title:'WEB', sub:'World Wide Web!'}
}
}
<Subject title = {this.state.subject.title}
sub = {this.state.subject.sub}></Subject>
- ์ฝ๋๋ฅผ ์ด๋ ๊ฒ ์์
- ์ ์ฝ๋์์ state ๊ฐ์ด subject๊ฐ ์๋์ง ์๋์ง ์ ์ ์์ โฌ ๋ด๋ถ์ ์ผ๋ก ์ ์ ์์
- ์ธ๋ถ์์ ์ ํ์ ์๋ ์ ๋ณด๋ฅผ ์ฒ ์ ํ๊ฒ ์๋ํ ์ ์๋ ๊ฒ
- ์์ Component์ State ๊ฐ์ ํ์ Component์ props ๊ฐ์ผ๋ก ์ ๋ฌํ๋ ๊ฒ ๊ฐ๋ฅ
React - 15.3. Key
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:'HTML is for design'},
{id:3, title:'JavaScript', desc:'HTML is for interactive'}
]
}
}
- ์ฝ๋ ์์
import { Component } from 'react';
class TOC extends Component{
render(){
var lists = [];
var data = this.props.data
var i = 0;
while(i < data.length){
// key ๊ฐ์ ์ง์ ํด ์ฃผ์ด์ผ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ง ์์
lists.push(<li key = {data[i].id}><a href = {"/contents/" + data[i].id}> {data[i].title} </a></li>);
i = i + 1;
}
return(
<ul>
{lists}
</ul>
);
}
}
export default TOC;
- TOC.js ํ์ผ
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:'HTML is for design'},
{id:3, title:'JavaScript', desc:'HTML is for interactive'}
]
}
}
- App.js ํ์ผ
'๐ STUDY > ๐ React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
- SpringBoot
- ํ๋ก์ธ์ค
- react-scripts
- SWiFT
- ๋ค์คํ๋ก์ธ์ค
- ํ๋ก๊ทธ๋๋ฐ
- Baekjoon
- 9086๋ฒ
- ํ์ผ ์ ์ถ๋ ฅ
- Programming
- machine learning
- ์ค๋ฅ
- error
- ๋จธ์ ๋ฌ๋
- ์๊ณ ๋ฆฌ์ฆ
- MySQL
- ๋ฆฌ๋ ์ค
- bitnami
- GIT
- ๋ฒํผ
- ๊ธฐ๊ณํ์ต
- C++
- ๋ฐฑ์ค
- C
- react
- Linux
- Annotation
- ์ค์น
- Apache
- PHP
- Total
- Today
- Yesterday