Property ‘currentUser’ does not exist on type ‘{}’. TS2339

I try to console.log currentUser (using Firebase).

This is the message I get from console:

    Property 'currentUser' does not exist on type '{}'.  TS2339

     7 |
     8 | function App() {
  >  9 |   const { currentUser } = useContext(SessionContext);
       |           ^
    10 |   console.log('currentuser', currentUser)
    11 |
    12 |   return (

Here is my SessionContext:

const SessionProvider = (children) => {
  const [currentUser, setCurrentUser] = useState(null);
  const [isReady, setIsReady] = useState(false);

 
  useEffect(() => {
    const handleAuthStateChanged = (user) => {
      setIsReady(true);
      setCurrentUser(user)

    };
    firebase.auth().onAuthStateChanged(handleAuthStateChanged);
  }, []);

  return (
    <SessionContext.Provider value={{ currentUser, isReady }}>
      {children}
    </SessionContext.Provider>
  );
};
export { SessionProvider };

Can anyone help me, how to make my code working? I try to find the solution for this error, but I cant find it anywhere.



Read more here: https://stackoverflow.com/questions/64893330/property-currentuser-does-not-exist-on-type-ts2339

Content Attribution

This content was originally published by Dima Malko at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: