
{}(중괄호)는 자바스크립트 식을 의미한다.
즉, jsx/tsx 파일 내에서 js 식을 사용하고 싶으면{}안에 작성하면 된다.
✅ 코드 중간에 js 식을 넣고 싶을 때는 (백틱)${}(백틱)을 사용한다.
React 파일은 jsx(js 사용 시), tsx(ts 사용 시) 이다. JSX란?
- 자바스크립트 파일 내에서 HTML같은 마크업을 작성할 수 있게 해주는 syntax extension이다.
(참고: jsx 관련 React 공식문서)
jsx/tsx 파일은 html element를 return하는 하나의 함수로 이루어진다.
따라서 이 html element 안에서 js 변수나 식을 사용하기 위해서는 js 식임을 표현하는 {} 로 감싸줘야 한다.
렌더링할 때 {} 내부에 있는 식을 평가(필요 시 연산도 진행)한다
tsx 파일이다).map 함수(js method)를 사용해야 하기에 {} 로 감싸서 사용했다.${}${} 를 사용할 때도 있다.className={col-${12/imgRow.length}}
function CardSkill({title, imgLs}: cardSkill) {
return (
<div className="mt-4">
<p className="ps-2 fs-5">{title}</p>
<div className="container rounded bg-blue p-3">
{imgLs && (
imgLs.map(imgRow => (
<div className="row justify-content-center">
{imgRow.map(imgStr => (
<div className={`col-${12/imgRow.length} text-center`}>
<img src={imgStr} alt="logo" className="w-50 my-1"/>
</div>
))}
</div>
))
)}
</div>
</div>
)
}
export default CardSkill
좋은 글이네요. 공유해주셔서 감사합니다.