Skip to content

Instantly share code, notes, and snippets.

@clairechabas
Created August 2, 2019 16:34
Show Gist options
  • Save clairechabas/3741ced966cf2dd13029ea3ab4625bbd to your computer and use it in GitHub Desktop.
Save clairechabas/3741ced966cf2dd13029ea3ab4625bbd to your computer and use it in GitHub Desktop.
Main.js component connected to Redux store to listen on the auth object from Firebase reducer to redirect the user according to auth status.
import React from "react";
import { connect } from "react-redux";
import Home from "./Home";
import Login from "./Login";
import Loader from "./Loader";
const Main = ({ auth }) => {
return (
<div>
{!auth.isLoaded ? <Loader /> : !auth.isEmpty ? <Home /> : <Login />}
</div>
);
};
function mapStateToProps(state) {
return {
auth: state.firebaseReducer.auth
};
}
export default connect(mapStateToProps)(Main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment