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

Styling in React

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

React မှာ style ရေးနည်းများစွာရှိပါတယ်။ Small project မှာ plain CSS လုံလောက်နိုင်ပြီး component-scoped style လိုချင်ရင် CSS Modules သုံးနိုင်ပါတယ်။ Design system ကြီးလာရင် Tailwind, styled-components, UI library စတာတွေကိုလိုအပ်သလိုရွေးနိုင်ပါတယ်။

jsx
// App.jsx
import './App.css';

function AlertBox() {
  return (
    <div className="alert-box">
      <strong>Tip:</strong> Component style ကို CSS file ထဲမှာခွဲရေးပါ။
    </div>
  );
}

// App.css
// .alert-box {
//   padding: 16px;
//   border-radius: 12px;
//   background: #eef6ff;
//   color: #102033;
// }

Component ထဲမှာ `className="alert-box"` ပေးပြီး CSS file ထဲမှာ `.alert-box` style ရေးထားပါတယ်။ ဒီနည်းက simple, readable, beginner-safe ဖြစ်ပါတယ်။

You should see
Padding, rounded corner, background color ပါတဲ့ tip box တစ်ခု ပေါ်လာမယ်။

Info

Inline style က dynamic value တစ်ခုနှစ်ခုအတွက်ကောင်းပေမယ့် design အများကြီးရေးရင် CSS file/class သုံးတာပိုသန့်ပါတယ်။

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

  • JSX မှာ `class="alert-box"` လို့ရေးမိတာ beginner တွေမှာအများဆုံးဖြစ်ပါတယ်။ React မှာ `className` ကိုသုံးပါ။
Styling in React | Thuta Learning