I have a hook I created to get my tags. I import this hook in my component, and call it on useeffect.
It is (supposed to be) exactly the same structure as my others hooks, that works fine, but this one throw an error as soon as I call it.
Here is the code of the hook :
I tried checking if my collection’s name is right, but it is.
export const useTagsCollection = () => {
const navigation = useNavigation();
const getTag = ({id, setTag}: useTagsCollectionGetTagProps) => {
firestore()
.collection('tags')
.doc(id)
.get()
.then(snapshot => {
const data = snapshot.data();
if (data) {
setTag(data as tagCollection);
}
})
.catch(error => {
navigation.navigate('Error', {error: error.toString()});
});
};
return {getTag};
};
And here is the implementation in my hook :
const [tag, setTag] = useState<tagCollection>();
const {getTag} = useTagsCollection();
useEffect(() => {
getTag({id: article.tags, setTag}); // send error function is undefined but why?
}, []);
I can also show you the types, in case there is a problem :
export interface tagCollection {
id: string;
title: string;
created_at: FirebaseFirestoreTypes.Timestamp;
}
export interface useTagsCollectionGetTagProps {
id: string;
setTag: Dispatch<SetStateAction<tagCollection | undefined>>;
}
I really can’t see the problem here, so it must be stupid.
Could you please help me ?
Thanks !