Thuta Learning
ရှာဖွေရန်
BasicWeb Developmentintermediate

Props

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Props သည် parent component က child component ဆီ data ပေးပို့တဲ့နည်းလမ်းပါ။ Component တစ်ခုကို template လိုရေးထားပြီး props အမျိုးမျိုးပေးလိုက်ရင် card title, price, image, button text စတာတွေကို လွယ်လွယ်ပြောင်းနိုင်ပါတယ်။

jsx
function CourseCard({ title, level, lessons }) {
  return (
    <article className="course-card">
      <h2>{title}</h2>
      <p>Level: {level}</p>
      <p>{lessons} lessons included</p>
    </article>
  );
}

function App() {
  return (
    <CourseCard
      title="React Foundation"
      level="Starter"
      lessons={18}
    />
  );
}

`CourseCard` က `title`, `level`, `lessons` ဆိုတဲ့ props သုံးခုကိုလက်ခံပါတယ်။ Parent ဖြစ်တဲ့ `App` က တန်ဖိုးတွေကို attribute ပုံစံနဲ့ပေးထားပါတယ်။

You should see
Course title, level, lessons count ပါတဲ့ card တစ်ခု ပေါ်လာမယ်။

Info

String props ကို quote နဲ့ပေးပြီး number, boolean, object, array props တွေကို `{}` ထဲမှာပေးပါတယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • `lessons=18` လို့ရေးမိရင် string handling မှားနိုင်ပါတယ်။ Number ပေးချင်ရင် `lessons={18}` လို့ရေးပါ။
Props | Thuta Learning