index.js 파일이 시작지점이다.
import React from "react";
import ReactDom from "react-dom/client";
function App() {
return <h1>Hello React!</h1>;
}
// React v18
const root = ReactDom.createRoot(document.getElementById("root"));
// id=root인 html을 불러와서 렌더링
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
parent components에서 child components로 data를 넘겨줄 때 사용한다.
Example 1
<Pizza
name="Pizza Prosciutto"
ingredients="omato, mozarella, ham, aragula, and burrata cheese"
photoName="pizzas/prosciutto.jpg"
price={10}
/>
Example 2
function SkillList() {
return (
<div className="skill-list">
<Skill skill="React" emoji="💘" color="skyblue" />
<Skill skill="JavaScript" emoji="💘" color="orange" />
<Skill skill="HTML+CSS" emoji="💘" color="yellow" />
</div>
);
}
function Skill(props) {
return (
<div className="skill" style={{ backgroundColor: props.color }}>
<span>{props.skill}</span>
<span>{props.emoji}</span>
</div>
);
}
className (not class)htmlFor (not for)<img />onClickaria-* and data-* are same as in HTML{{<style>}} (to reference a variable, and then an object)각각 레벨에 다른 이모지 출력
&&: 조건이 true이면 뒷부분 실행, false이면 pass.
<span>
{level === "beginner" && "🐣"}
{level === "intermediate" && "😊"}
{level === "advanced" && "💪"}
</span>