React/일반
리액트에서 자식을 포함한 엘리먼트 추가 방법
Socratone
2020. 4. 4. 20:03
counter.jsx
import React, { Component } from 'react';
class Counter extends Component {
render() {
// return되는 부모 엘리먼트는 하나만 올 수 있고
// <React.Fragment>로 감싸주면 자식들을 넣을 수 있다.
// <React.Fragment>는 렌더링시 포함되지 않는다.
return (
<React.Fragment>
<h1>Hello World</h1>
<button>Button</button>
</React.Fragment>
);
}
}
export default Counter;