반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- route
- nodeJS
- priority_queue
- Context
- Callback
- treenode
- event
- map
- MySQL
- state
- axios
- component
- server
- css
- bit
- leetcode
- Navigation
- Props
- node.js
- routes
- BinaryTree
- c++
- count
- array
- JSX
- React
- queue
- UE5
- DP
- 비트연산
Archives
- Today
- Total
우사미 코딩
[React] props 사용하기 본문
반응형
1. App.js
import ProfileCard from "./ProfileCard";
function App(){
return(
<div>
<div>Personal Digital Assistance</div>
<ProfileCard title = "Alexa" handle="@alexa123"/>
<ProfileCard title = "Cortana" handle="@cortana32"/>
<ProfileCard title = "Siri" handle="@siri01"/>
</div>
);
}
export default App;
src파일에 ProfileCard.js라는걸 만들었고
이 컴포넌트의 props로 title, handle정보를 넘겨줄 것이다
2. ProfileCard.js
// function ProfileCard(props){ // 아래와 동일
function ProfileCard({title, handle}){
// const title = props.title;
// const handle = props.handle;
// const { title, handle } = props; // 100% equals with line3~4
return (
<div>
<div>Title is {title}</div>
<div>Handle is {handle}</div>
</div>
);
}
export default ProfileCard;
인자(argument)를 object로 받을 때 component에서 표시할 수 있는 방법이 몇 개 있는데,
function ProfileCard(props)와 같이 변수명으로 받아도 되지만 ProfileCard({ title, handle }) 로 표현할 수 있고 이 방법을 상당히 많이 쓴다고 한다. (사실 이건 jsx기능은 아니고 자바스크립트 기능이라고 함 ㅋ)
ㅇㅈ props.title, props.handle로 사용하는 것보다 훨씬 편하긴 함
반응형
'React' 카테고리의 다른 글
| [React] 프로젝트에 이미지 추가하고 불러오기 (0) | 2023.06.22 |
|---|---|
| [React] 관리자모드에서 component 확인하기 (ft. 크롬 확장 프로그램) (0) | 2023.06.22 |
| [React] jsx의 경로와 import, export (0) | 2023.06.22 |
| [React] Jsx - converting HTML to JSX (0) | 2023.06.21 |
| [React] jsx에 대해 알아보자! 변수 선언과 활용 (0) | 2023.06.21 |
Comments