I am confused about the export magic in the following code from this tutorial (available at GitHub):
import React, { Component } from 'react';
import withFirebaseAuth from 'react-with-firebase-auth'
import firebase from 'firebase/app';
import 'firebase/auth';
import firebaseConfig from './firebaseConfig';
import logo from './logo.svg';
import './App.css';
const firebaseApp = firebase.initializeApp(firebaseConfig);
class App extends Component {
render() {
const {
user,
signOut,
signInWithGoogle,
} = this.props;
if (user) {
console.log(user.uid);
}
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
{
user
? <p>Hello, {user.displayName}</p>
: <p>Please sign in.</p>
}
{
user
? <button onClick={signOut}>Sign out</button>
: <button onClick={signInWithGoogle}>Sign in with Google</button>
}
</header>
</div>
);
}
}
const firebaseAppAuth = firebaseApp.auth();
const providers = {
googleProvider: new firebase.auth.GoogleAuthProvider(),
};
export default withFirebaseAuth({
providers,
firebaseAppAuth,
})(App);
I do not understand (1) how come App.props has new members and (2) how come these new members are not undefined at the beginning of App.render(). In more detail:
- According to the documentation, I understand that the call to
withFireBaseAuth()inexportreturns a function, which, when called withAppas an argument, returns a component. However, it is a new component. So, how comepropsget added toApp? - The call to
withFireBaseAuth()appears after the definition ofApp, so how comeApp.props.useris not undefined when it is used inApp.render()?