반응형
JSX 코드 => React엔진이 이해하지 못 함.
JSX 코드 => Babel 번역 => React엔진이 이해할 수 있게 번역됨.
JSX 코드는 대다수의 리액트 개발자들이 사용하는 코드 작성 법으로
리액트 코드를 HTML코드처럼 짤 수 있게 해준다.
아래의 JSX 코드와 Babel 번역 코드를 보면
JSX 문법이 React.createElement와 같은 방식으로 변환된 것을 알 수 있다.
// JSX 코드
const Title = (
<h3
id="title"
onMouseEnter={() => {
console.log("mouse enter");
}}
>
Hello I'm a title
</h3>
);
const Button = (
<button
id="button"
style={{ backgroundColor: "tomato" }}
onClick={() => {
console.log("click button");
}}
>
Click me
</button>
);
// Babel 번역 코드
"use strict";
const Title = /*#__PURE__*/React.createElement("h3", {
id: "title",
onMouseEnter: () => {
console.log("mouse enter");
}
}, "Hello I'm a title");
const Button = /*#__PURE__*/React.createElement("button", {
id: "button",
style: {
backgroundColor: "tomato"
},
onClick: () => {
console.log("click button");
}
}, "Click me");
반응형
'개발 저장소 > 개발 지식 저장소' 카테고리의 다른 글
[React.js] input 입력 값 가져오기(SyntheticBaseEvent) (0) | 2022.12.13 |
---|---|
[React.js] useState 선언 방법 (0) | 2022.12.13 |
[React.js] styled-component 설치 후 글자 테마 변경(vscode-styled-component) (0) | 2022.12.12 |
[npm] npm install 할 때 unable to resolve dependency tree 오류 (0) | 2022.12.12 |
[React.js] 목록을 mapping할 때는 key값 할당 필요 (0) | 2022.12.12 |