JavaScript Library ለ UI መስራት! 🔥
The most popular JavaScript library for building user interfaces!
React — Facebook (Meta) የሰራው JavaScript Library ነው። UI (User Interface) ን Components ተጠቅሞ ለመስራት ይጠቅማል!
React is a JavaScript library made by Meta (Facebook) for building user interfaces using reusable components.
React = Component-based — page ን ትናንሽ ቁርጥራጮች (Components) ሆነው ትሰራለህ። እያንዳንዱ Component ብቻውን ይሰራና ደጋግሞ ይጠቀማል!
Build pages as small reusable pieces called components — like LEGO blocks!
Vanilla JS vs React — ልዩነቱ ምንድን ነው?
Component = ደጋግሞ ጥቅም ላይ የሚውል UI ቁራጭ። Button, Card, Header — ሁሉም Component ሊሆን ይችላል!
A component is a reusable piece of UI — like a function that returns HTML!
🌳 Component Tree — App ዛፍ:
// React Component — function ነው JSX የሚመልስ function Welcome() { return ( <div> <h1>ሰላም React! 👋</h1> <p>EthioCode ትምህርት</p> </div> ); } // Component ለመጠቀም tag ሆኖ ይጻፋል function App() { return ( <div> <Welcome /> // Component ጥቅም ላይ ዋለ! <Welcome /> // ደጋግሞ ጥቅም ላይ ዋለ! </div> ); }
Props = Properties — ወላጅ Component ልጅ Component ን ውሂብ ለማስተላለፍ ይጠቅማል! HTML attribute ይመስላል።
Props pass data from parent to child component — like HTML attributes!
// Props ተቀብሎ የሚጠቀም Component function ProfileCard({ name, role, emoji }) { return ( <div className="card"> <div className="avatar">{emoji}</div> <h3>{name}</h3> <p>{role}</p> </div> ); } // App — ሁሉም cards አንድ Component ይጠቀማሉ! function App() { return ( <div> <ProfileCard name="Abel" role="Developer" emoji="👨💻" /> <ProfileCard name="Sara" role="Designer" emoji="🎨" /> </div> ); }
🎮 Demo — Props ውጤት: አንድ Component ሶስት ጊዜ ጥቅም ላይ ዋለ!
Same component reused 3 times with different props!
useState = React Hook — Component ውስጥ ውሂብ ለማስቀመጥ ይጠቅማል። State ሲቀየር React ራሱ UI ን ያዘምናል!
useState is a React Hook that lets components remember values. When state changes, React automatically re-renders!
import { useState } from 'react'; function Counter() { // count = current value, setCount = ለመቀየር const [count, setCount] = useState(0); return ( <div> <h2>{count}</h2> <button onClick={() => setCount(count + 1)}> + ጨምር </button> <button onClick={() => setCount(count - 1)}> - ቀንስ </button> <button onClick={() => setCount(0)}> Reset </button> </div> ); }
🎮 Demo — Counter (useState ምሳሌ):
This is exactly what the React Counter component above does!
UI ን ትናንሽ Components ሆነው ትሰራለህ — ደጋግሞ ጥቅም ላይ ይውላሉ!
Build UI from small reusable components.
function ሆኖ ይፃፋል፣ JSX (HTML-like) ይመልሳል። ስም ትልቅ ፊደል ይጀምራል — <MyComponent />
Components are functions that return JSX. Names start with capital letter.
ወላጅ ልጅ Component ን props ይሰጣል — <Card name="Abel" />
Props pass data from parent to child — like function arguments.
const [value, setValue] = useState(initial) — state ሲቀየር React UI ን ያዘምናል!
useState stores data. When it changes, React re-renders automatically.