from '../Firebase';
const withAuthentication = (Component) => {
class WithAuthentication extends React.Component {
constructor(props) {
super(props);
this.state = {
authUser: null,
};
}
componentDidMount() {
const authUser = auth.getCurrentUser()
authUser
? this.setState({ authUser })
: this.setState({ authUser: null });
},
);
}
componentWillUnmount() {
this.listener();
}
render() {
return (
<AuthUserContext.Provider value={this.state.authUser}>
<Component {...this.props} />
</AuthUserContext.Provider>
);
}
}
return withFirebase(WithAuthentication);
};
export default withAuthentication;
Very confusing indirection here
why, i dont understand, can you explain
withAuthentication is a function that takes a Component, and returns the returned value from withFirebase which takes the class you define inline in the function
Обсуждают сегодня