React & React Native

useState

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

useState i jep një komponenti memorie: const [vlera, setVlera] = useState(fillimi). Kur thërret setVlera, React-i e rishfaq komponentin me vlerën e re.

EnglishEN

useState gives a component memory: const [value, setValue] = useState(initial). When you call setValue, React re-renders the component with the new value.

Si ta mendosh

Si tabela e rezultatit: sa herë ndryshon, ekrani përditësohet.

Lexoje në anglisht

Like a scoreboard: every time it changes, the screen updates.

Shembull kodijavascript

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

Terma të lidhur