JavaScript

React hooks (useState, useEffect)

Në shqip: Hooks në React

ShpjegimiSQ

Hooks janë funksionet speciale të React-it që fillojnë me „use“. useState i jep një komponenti memorie (p.sh. një numërues), dhe useEffect ekzekuton kod pasi komponenti shfaqet — p.sh. për të marrë të dhëna nga një API.

EnglishEN

Hooks are React's special functions starting with “use”. useState gives a component memory (like a counter), and useEffect runs code after the component appears — like fetching data from an API.

Si ta mendosh

useState është si tabela e rezultatit në stadium: sa herë ndryshon, ekrani përditësohet vetë.

Lexoje në anglisht

useState is like the stadium scoreboard: every time it changes, the screen updates itself.

Shembull kodijavascript

function Numeruesi() {
  const [gola, setGola] = useState(0);
  return <button onClick={() => setGola(gola + 1)}>Gola: {gola}</button>;
}

Terma të lidhur