import React from 'react';
import Hello from "components/Hello";
function App() {
return (
<Hello name="react" />
);
}
export default App;
import React from 'react';
const Hello = (props)=> {
return <div>안녕하세요 {props.name}</div>
}
export default Hello;
import React from "react";
const Hi = ({ color, text }) => {
return <div style={{ color: color }}>{text}</div>;
};
export default Hi;
import React from "react";
import Hello from "./components/Hello";
import Hi from "./components/Hi";
function App() {
return (
<>
<Hello name="react" />
<Hi text="안녕 파랑색" color="blue" />
</>
);
}
export default App;
import React from 'react';
const Hi = ({ color, name }) {
return <div style={{ color }}>안녕하세요 {name}</div>
}
Hi.defaultProps = {
name: '이름없음'
}
export default Hello;
import React from "react";
import Hello from "./components/Hello";
import Hi from "./components/Hi";
function App() {
return (
<>
<Hello name="react" />
<Hi text="안녕 파랑색" color="blue" />
<Hi></Hi>
</>
);
}
export default App;
컴포넌트 태그 사이에 넣은 값을 조회 할떈, props.children을 사용한다.
const Wrapper = ({ children }) => {
const style = {
border: "2px solid black",
padding: "16px",
};
return <div style={style}>{children}</div>;
};
export default Wrapper;
import React from "react";
import Hello from "./components/Hello";
import Hi from "./components/Hi";
import Wrapper from "./components/Wrapper";
function App() {
return (
<Wrapper>
<Hello name="react" />
<Hi text="안녕 파랑색" color="blue" />
<Hi></Hi>
</Wrapper>
);
}
export default App;