I'm pretty new at typescript and migrating my react app to using ts.
I'm using the firebase auth service and I'm facing some type issues which I can't seem to get around. Please advise!
import React, { useEffect, useState } from 'react';
import app from './firebase';
export const AuthContext = React.createContext(null);
export const AuthProvider: React.FC<Props> = ({ children }) => {
const [currentUser, setCurrentUser] = useState(null);
const [pending, setPending] = useState(true);
useEffect(() => {
app.auth().onAuthStateChanged((user) => {
// ts error here
setCurrentUser(user);
setPending(false);
});
}, []);
if(pending){
return <>Loading...</>;
}
return (
<AuthContext.Provider
// ts error here
value={{ currentUser }}
>
{children}
</AuthContext.Provider>
);
};
interface Props {
children: React.ReactNode;
}
setCurrentUser(user); is giving me an error of
Argument of type 'User | null' is not assignable to parameter of type 'SetStateAction<null>'.
and
value={{ currentUser }} is giving me an error of Type '{ currentUser: null; }' is not assignable to type 'null'.