//class형
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
//function 형
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
function User(props){
return <h1> Welcome ! {props.user} </h1>
}
const element= <User user="eunsu" />
const rootElement = document.getElementById("root");
ReactDOM.render(
element, rootElement
);
<User user="eunsu" />
엘리먼트로 ReactDOM.render()호출{user:eunsu} props로 전달 User function 호출User함수의 반환값으로 <h1>Welcome! eunsu</h1>
반환 React.DOM에 랜더링되서 index.html에 출력function Children1() {
return (
<div className="children1">
<div>2</div>
</div>
);
}
function Children2() {
return (
<div>
<div>3</div>
</div>
);
}
function Children3() {
return (
<div>
<div>4</div>
</div>
);
}
function Parents(children){
return(
<div>
<div>1</div>
{children}
<div>5</div>
</div>
)
}
exports default function App(){
return(
<Parents>
<p>3</p>
<Parents>
)
}
*Box.jsx
import BoxItems from "./BoxItems";
export default function Box() {
const user = [
{
name: "Judy",
age: 15,
gender: "female"
},
{
name: "Holy",
age: 23,
gender: "male"
}
];
return (
<>
<BoxItems>
{user.map((item) => (
<>
<p>Name: {item.name} </p>
<p> Age: {item.age} </p>
</>
))}
</BoxItems>
</>
);
}
*BoxItems.jsx
const BoxItems= ({children}) => {
return (
<div>
<h1>Welcome to World!</h1>
{children}
</div>
)
}
export default BoxItems;