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

What is React?

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

React သည် user interface တည်ဆောက်ရန် အသုံးများတဲ့ open-source JavaScript library ဖြစ်ပါတယ်။ Website တစ်ခုမှာ header, card, button, product list, profile box စတဲ့ UI အပိုင်းတွေကို component လေးတွေခွဲပြီး တည်ဆောက်နိုင်တာကြောင့် code ကိုပြန်သုံးရလွယ်ပြီး project ကြီးလာလည်း ထိန်းရလွယ်ပါတယ်။

jsx
import React from 'react';
import ReactDOM from 'react-dom/client';

function App() {
  return <h1>Hello, React!</h1>;
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

ဒီ code မှာ `App` ဆိုတဲ့ component တစ်ခုရေးထားပြီး `

Hello, React!

` ကို return ပြန်ထားပါတယ်။ နောက်ဆုံး `root.render()` က App component ကို HTML ထဲက `id="root"` element အတွင်း render လုပ်ပေးပါတယ်။

You should see
Browser ထဲမှာ `Hello, React!` ဆိုတဲ့ heading တစ်ခု ပေါ်လာမယ်။

Info

Component name ကို စာလုံးအကြီးနဲ့စရေးတာ React ရဲ့ convention ပါ။ `App` ကို `` လို့ HTML tag ပုံစံခေါ်သုံးနိုင်တာက JSX ကြောင့်ပါ။

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

  • `document.getElementById('root')` ထဲက `root` ဟာ `index.html` ထဲမှာရှိတဲ့ id နဲ့တူရပါမယ်။ မတူရင် app မပေါ်နိုင်ပါ။
What is React? | Thuta Learning