React에서 자식컴포넌트를 상위컴포너트를 감싸는방법

 

App.js

import Wrapper from './Wrapper';
function App(props) {
return (
// Wrapper라는 컴포넌트로 하위 컴포넌트를 감싸준다.
<Wrapper>
<Hello name="react" color="red" isSpecial={true} />
<Hello color="pink" />
</Wrapper>
);
}
export default App;

 

Wrapper.js

import React from 'react';
// 받을때 children 객체를 받는다.
function Wrapper({children}) {
const style = {
border: '2px solid black',
padding: 16
};
// 해당 항목에 추가해준다.
return <div style={style}>{children}</div>
}
export default Wrapper;

 

'SPA > React.js' 카테고리의 다른 글

className (클래스 네임)  (0) 2021.05.12
React Array (배열 출력)  (0) 2021.05.11
Input value control (input 상태 관리)  (0) 2021.05.09
Comment (주석)  (0) 2021.05.08
React props 1  (0) 2021.05.07