Typing React hooks
Në shqip: Tipet te hooks-et e React-it
ShpjegimiSQ
Me TypeScript, useState e kupton vetë tipin nga vlera fillestare. Kur vlera fillestare është null ose varg bosh, jepja tipin vetë: useState<Termi | null>(null).
EnglishEN
With TypeScript, useState infers the type from the initial value. When the initial value is null or an empty array, give the type yourself: useState<Term | null>(null).
Si ta mendosh
Si të shënosh në kavanoz bosh çfarë do të fusësh më vonë.
Lexoje në anglisht
Like labelling an empty jar with what you'll put in it later.
Shembull koditypescript
const [termi, setTermi] = useState<Termi | null>(null);
const [lista, setLista] = useState<Termi[]>([]);
const ref = useRef<HTMLInputElement>(null);