: 자바스크립트의 확장 문법
: 기존의 자바스크립트 문법을 사용자에게 더 명시적이고 명확하게 표현
- 전체 코드를 감싸주는 최상위 태그가 있어야함
예
- 맞는 코드
function App() {
return (
<div className="App">
<h1>hello react</h1>
<p>반갑습니다.</p>
</div>
);
}
- 틀린 코드
function App() {
return (
<div className="App">
<h1>hello react</h1>
<p>반갑습니다.</p>
</div>
<div>
오류 --> div가 병렬로 존재 >
</div>
);
}
인라인 스타일
: 컴포넌트 안에서 스타일 지정
function App() {
let name = "리액트";
const style = {
backgroundColor: "black",
color: "white",
fontSize: "48px",
fontWeight: "bold",
padding: "20px",
};
return (
<div style={style}>
<h1 style={style}>
hello
{name === "리액트" ? <h1>YES</h1> : null}
</h1>
<p>반갑습니다.</p>
</div>
);
}
- 이렇게 해도됨
<div
style={{
backgroundColor: "black",
color: "white",
fontSize: "48px",
fontWeight: "bold",
padding: "20px",
}}
>
<h1 style={style}>
hello
{name === "리액트" ? <h1>YES</h1> : null}
</h1>
<p>반갑습니다.</p>
</div>
-주석
/* 설명 */
'데브코스 > 강의 정리' 카테고리의 다른 글
props, 공부 방향 (0) | 2024.11.01 |
---|---|
11주차 파트 4 (0) | 2024.10.31 |
리액트란 / 초기설정 / 기본 코드 분석 (0) | 2024.10.30 |
클래스와 객체, 생성자, 접근지정자, getter와 setter (0) | 2024.10.29 |
리터럴, any, 유니온, array, tuple (0) | 2024.10.29 |