مثال JavaScript: <script type="text/jsx"> — پروژه: کارت معرفی من
مثال 3 از درس جلسهی 5 آموزش ریاکت (React) از صفر برای نوجوانان، قطعه به قطعه: پروژه: کارت معرفی من
کارت تمامشده این شکلی است. اجرایش کن و ببین هر تکهی صفحه از کدام کامپوننت میآید. بعد از پروژه اسم، شهر و مهارتهای خودت را جایشان بگذار.
<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.card { max-width: 260px; margin: 12px auto; padding: 16px; border: 2px solid #334155; border-radius: 16px; background: #f8fafc; }
.avatar { font-size: 64px; }
.badge { display: inline-block; margin: 4px; padding: 4px 12px; border-radius: 999px; background: #bae6fd; }
.gold { color: goldenrod; }
.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
</style>
<div id="root" dir="ltr"></div>
<script type="text/jsx">
import { createRoot } from "react-dom/client";
function Avatar() {
return <p className="avatar">🦊</p>;
}
function Name() {
return <h2 id="name">Sara</h2>;
}
function Bio() {
const age = 13;
const city = "Tabriz";
return <p id="bio">{age} years old, from {city}</p>;
}
function Skills() {
return (
<div id="skills" className="row">
<span className="badge">HTML</span>
<span className="badge">CSS</span>
<span className="badge">React</span>
</div>
);
}
function Footer() {
return <p id="foot" className="gold">Made with React</p>;
}
function App() {
const color = "tomato";
return (
<div id="card" className="card" style={{ borderColor: color }}>
<Avatar />
<Name />
<Bio />
<Skills />
<Footer />
</div>
);
}
createRoot(document.getElementById("root")).render(<App />);
</script>
این کد را همینجا در ویرایشگر HTML اجرا کن، عددها و متنهایش را عوض کن و دوباره اجرا کن تا ببینی چه تغییری میکند.
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js
برگشت به درس جلسهی 5: پروژه: کارت معرفی من · چالشهای این جلسه