Skip to content
Randula Wickramasuriya edited this page Jul 13, 2020 · 3 revisions

AccessCurrent User

Access in Class components (In the beginning of the class)

static contextType = UserContext;

Use in html:

{this.context.state}

Get user when page load (in ComponentDidMount method)


async componentDidMount() {

const userData = await this.context.currentUser();

this.setState(userData);

}


Access in Functional components

const context = useContext(UserContext);

Use in html:

{context.state}