React & React Native

Custom hooks

Në shqip: Hooks-et e tua

ShpjegimiSQ

Një custom hook është funksioni yt që fillon me „use“ dhe përdor hooks të tjera brenda. Kështu e ndan logjikën e përsëritur — p.sh. useLocalStorage ose useDebounce — mes shumë komponentëve.

EnglishEN

A custom hook is your own function starting with “use” that uses other hooks inside. That's how you share repeated logic — e.g. useLocalStorage or useDebounce — across many components.

Si ta mendosh

Si një recetë e vogël që e përdor në shumë gjella.

Lexoje në anglisht

Like a small recipe you use in lots of dishes.

Shembull kodijavascript

function useMadhesiaEDritares() {
  const [w, setW] = useState(window.innerWidth);
  useEffect(() => { const f = () => setW(window.innerWidth); addEventListener("resize", f); return () => removeEventListener("resize", f); }, []);
  return w;
}

Terma të lidhur