TypeScript

Typing useState & useRef

Në shqip: Tipet për useState dhe useRef

ShpjegimiSQ

useState zakonisht e nxjerr tipin vetë, por kur vlera fillestare është null shkruaje: useState<Nxenes | null>(null). Për referenca DOM: useRef<HTMLInputElement>(null).

EnglishEN

useState usually infers its type, but when the initial value is null write it out: useState<Student | null>(null). For DOM refs: useRef<HTMLInputElement>(null).

Si ta mendosh

Si t'i vësh etiketë kutisë bosh që të dish çfarë do të futet më vonë.

Lexoje në anglisht

Like labelling an empty box so you know what will go in later.

Shembull koditypescript

const [nx, setNx] = useState<Nxenes | null>(null);
const input = useRef<HTMLInputElement>(null);
input.current?.focus();

Terma të lidhur