๋ฆฌ์กํธ ๋ฐฐ์ด ๋ค๋ฃจ๊ธฐ
Component ์ ์ธ, ์ฌ์ฌ์ฉ
์์คํ
์ํํธ์จ์ด - ์ด์์ฒด์ ๋ฅผ ๋ง๋ค๊ฑฐ๋ ํ๋....
SPA(Single Page Application) - ์์ฉ ํ๋ก๊ทธ๋จ์ ๋ง๋ค๊ฑฐ๋ ํ๋....(๋ฆฌ์กํธ๋ ์ฌ๊ธฐ์ ํด๋น)
๋น ๋ฅธ ํน์ง์ด ์๋ค.
๋ฐ์ดํฐ ๋น์ฉ ์ ๊ฐ
ํด๋ฆญํ๋ฉด ์๋ฒ์ ๋ํ ์์ฒญ์ด ์๋๋ผ ์ปดํฌ๋ํธ๋ง ๋ฐ๋๊ฒ๋
์๋ฒ์ธก ๋ฐ์ดํฐ๋ฅผ ์ฉ์ฒญํ ๋๋ ajax ์ฌ์ฉ
๋ฐฐ์ด ๋ค๋ฃจ๊ธฐ
-๋ก์ปฌ์ ์ ์ธ๋ ๋ฐฐ์ด
-back end ์์ ์ ๋ฌํ ๋ฐฐ์ด (๋ฆฌ์คํธ)
1
2
3
4
5
|
list.map(f); *f๋ list ์ ์์ ๊ฐ๊ฐ์ ๋ฐ์์ ๊ฐ๊ณตํ๊ณ ๋ค์ ๋ฐฐ์ด๋ก ๋ฆฌํด
(v) => <div>{v}</div>
list.map( (v) => <div>{v}</div> )
|
cs |
-list.map(f); /* f๋ list์ ์์ ๊ฐ๊ฐ์ ๋ฐ์์ ๊ฐ๊ณตํ๊ณ ๋ค์ ๋ฐฐ์ด๋ก ๋ฆฌํด
App.js
1
2
3
4
5
6
7
8
9
10
11
|
import Input from './comp/Input.js'
import ShowArr from './comp/ShowArr.js'
function App(){
return(
<div className='App'>
<Input/>
<ShowArr/>
</div>
);
}
export default App;
|
cs |
Input.js
1
2
3
4
5
6
7
8
9
10
11
12
13
|
function Input(){ //jsx = javascript +xml
function onChange(evt){
let val = evt.target.value;
console.log("์
๋ ฅ๋ ๊ฐ"+ val);
}
return(
//์ปดํฌ๋ํธ๊ฐ ํ๋ฉด์ ๋ณด์ฌ์ค ๋ด์ฉ(html ํ์ฅ xml, attributes)
<input type={"text"} value="" onChange={onChange}></input>
);
}
export default Input;
|
cs |
ShowArr.js
1
2
3
4
5
6
7
8
|
function ShowArr(){
const title = "๋ฐฐ์ด ๋ค๋ฃจ๊ธฐ";
const names =["Smith","Jone","Ward"];
return(
names.map(name => <div key={name}>{name}</div>)
);
}
export default ShowArr;
|
cs |
1
2
3
4
5
|
return(
names.map( nm => {
return (<div key={nm}>{nm}</div>)
})
)
|
cs |
๋ฌธ์ฅ์ด ๋ค์ค๋ฌธ์ฅ์ผ ๊ฒฝ์ฐ {}์ฌ์ฉํ๋ค. ๊ทธ ์์์ ํ ๋ฌธ์ฅ์ด return์ด ๋์ผํ๋ค.
์คํ๊ฒฐ๊ณผ :
๋๊ธ