Typing React context
Në shqip: Tipet për Context-in e React
ShpjegimiSQ
Me createContext<Tema | null>(null) dhe një hook që hedh gabim kur context-i mungon, merr tipe të sakta kudo pa kontrolle null të përsëritura.
EnglishEN
With createContext<Theme | null>(null) and a hook that throws when the context is missing, you get exact types everywhere without repeated null checks.
Si ta mendosh
Si një rrjet WiFi me fjalëkalim: kush është brenda, e ka gjithmonë lidhjen.
Lexoje në anglisht
Like a password-protected WiFi: whoever's inside always has the connection.
Shembull koditypescript
const TemaCtx = createContext<{ tema: string } | null>(null);
function useTema() {
const c = useContext(TemaCtx);
if (!c) throw new Error("Mungon TemaProvider");
return c; }