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 |
Tags
- mysql
- instruction
- Pipelining
- CSS
- system
- php
- DB
- python
- computer
- data structure
- Class
- MacOS
- XML
- for
- while
- github
- Java
- DS
- DATAPATH
- javascript
- Linux
- DoM
- control
- Algorithm
- react
- html
- MIPS
- function
- web
- architecture
Archives
- Today
- Total
YYYEJI
[React] JSX 태그 내부에서 변수 사용하기 본문
728x90

React(리액트)에서 변수는 return 위에서 생성됩니다.
function Question() {
return (
<div className="question">
<h2>Question</h2>
</div>
);
}
아래와 같이 변수를 선언합니다.
const str1="Hello"
const str2="1"
let num = 1
function Question() {
const count = 0
return (
<div className="question">
<h2>Question {count}</h2>
</div>
);
}
let 타입은 선언 이후에 값이 변할 수 있음을 의미합니다.
(const는 선언 이후에 값이 변할 수 없습니다!)
변수에 목적에 맞게 타입을 지정해서 변수를 정의해주면 됩니다.
function Question() {
let count = 1
return (
<div className="question">
<h2>Question {count}</h2>
</div>
);
}
변수를 사용할 땐 {중괄호}에 변수 이름을 넣으면 됩니다.
◡̈
'Web Application Server (WAS)' 카테고리의 다른 글
[API KEY] 카카오 API 키 발급 받는 방법 (0) | 2023.01.11 |
---|---|
[React] yarn으로 styled-components 설치하기 (0) | 2023.01.10 |
[React] 리액트(React)에서 이미지 넣기 (0) | 2023.01.10 |
[React] JSX expressions must have one parent element 에러 (0) | 2023.01.10 |
[React] event.target.value 란? (0) | 2023.01.06 |