React & React Native

AppState (foreground & background)

Në shqip: Gjendja e aplikacionit

ShpjegimiSQ

AppState të tregon nëse aplikacioni është në ekran (active), në sfond (background) apo duke kaluar mes tyre. E përdor për të ruajtur punën kur përdoruesi del, ose për t'i rifreskuar të dhënat kur kthehet.

EnglishEN

AppState tells you whether the app is on screen (active), in the background or switching between them. You use it to save work when the user leaves, or refresh data when they come back.

Si ta mendosh

Si dyqani që i ndez dritat kur hyn klienti dhe i fik kur del.

Lexoje në anglisht

Like a shop that turns the lights on when a customer comes in and off when they leave.

Shembull kodijavascript

useEffect(() => {
  const s = AppState.addEventListener("change", (g) => g === "active" && rifresko());
  return () => s.remove();
}, []);

Terma të lidhur