본문 바로가기

Web/React.js

[React.js] Fragment

React에서 두 개 이상의 엘리먼트는 무조건 하나의 엘리먼트로 감싸져 있어야 한다.

<div>
	<h1>test</h1>
	<button>click</button>
<div>

위와 같은 경우에는 보통 div 태그로 많이 감싼다.

 

다른 태그로 감쌀 필요성이 있는 경우 Fragment를 사용한다.

<>
	<h1>test</h1>
	<button>click</button>
</>

별도의 노드를 작성하지 않고도 자식 노드를 그룹화할 수 있다.

 

 

https://reactjs-kr.firebaseapp.com/docs/fragments.html

 

Fragments – React

A JavaScript library for building user interfaces

reactjs.org