I am trying to use the value of currentUser in the function inside of the useEffect Hook, but the value seems not to be the user's object, that I want it to be when using it. Here is the code:
function Chat() {
const currentUser = useAuth()
useEffect(() => {
const fetchParticipants = async () => {
console.log(currentUser.uid) // not defined
}
fetchParticipants()
}, [])
}
That is the useAuth() function that is being called
export function useAuth() {
const [ currentUser, setCurrentUser ] = useState();
useEffect(() => {
const unsub = onAuthStateChanged(auth, user => setCurrentUser(user));
return unsub;
}, [])
return currentUser;
}