Closed
Description
React version: 16.13.1
Steps To Reproduce
- Create function with generic type parameter
- Use that generic type parameter in
useCallback
,useEffect
oruseMemo
Example:
export function useDocument<TDocument>(path: string, defaultValue: TDocument | undefined = undefined): TDocument | undefined {
const [value, setValue] = useState<TDocument | undefined>(defaultValue);
const onNext = useCallback((snapshot: FirebaseFirestoreTypes.DocumentSnapshot<FirebaseFirestoreTypes.DocumentData>) => {
if (snapshot.exists) setValue(build<TDocument>(snapshot.data(), snapshot.id));
else setValue(undefined);
}, []);
useEffect(() => firestore().doc(path).onSnapshot(onNext), [onNext, path]);
return value;
}
The current behavior
Shows error React Hook useCallback has a missing dependency: 'TDocument'. Either include it or remove the dependency array.eslintreact-hooks/exhaustive-deps)
The expected behavior
Should not show any errors, because it isn't possible to add types to the dependencies array (types don't exist at runtime!)