0% found this document useful (0 votes)
10 views1 page

Userprovider

Uploaded by

Dylan Chaos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Userprovider

Uploaded by

Dylan Chaos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import React, { Component, createContext } from "react";

import { auth, createUserDocument } from "../firebase";

export const UserContext = createContext({ user: null });

class UserProvider extends Component {


state = { user: null, loading: true };

componentDidMount = async () => {


[Link] = [Link](async (user) => {
[Link]("changed")
if (user) {
[Link]("authUser", [Link](user));
const userDocument = await createUserDocument(user);
return [Link]({ user: userDocument, loading: false });
}
[Link]("authUser");
[Link]("loging out");
[Link]({ user: null });
});
};
componentWillUnmount = () => {
[Link]();
};

render() {
const { children } = [Link];
const { user, loading } = [Link];
//if (loading) return <div>Loading...</div>;
return <[Link] value={user}>{children}</[Link]>;
}
}

export default UserProvider;

You might also like