I am building a simple to do app, and I have implemented a simple conditional rendering scheme, where I log "Hello world" if user is not authenticated, and I show the page if it is authenticated. However, even when the user is logged in, the "Hello world" is still logged to the console. Here is my code
import React, { useState, useEffect } from "react";
import Tasks from "../tasks";
import { IoIosArrowBack } from "react-icons/io";
import { Link } from "react-router-dom";
import { auth } from "../../firebase";
import { onAuthStateChanged} from "firebase/auth";
const History = ({ tasks }) => {
const [authUser, setAuthUser] = useState(null);
useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (user) => {
setAuthUser(user);
});
return () => {
unsubscribe();
};
}, []);
return (
<div>
{authUser ? (<React.Fragment>
<div className="navbar">
<Link to="/home" className="navbar-left">
<IoIosArrowBack style={{ fontSize: "35px" }} />
</Link>
<div className="navbar-right">
<div className="navbar-subtext">Finished tasks</div>
<div className="navbar-ut">
{tasks.filter((t) => t.completed === true).length}
</div>
</div>
</div>
<br />
<hr />
<Tasks
tasks={tasks}
remainingTasks={tasks.filter((t) => t.completed === true).length}
showCompleted={true}
/>
</React.Fragment>) : (console.log("Hello World"))}
</div>
);
};
export default History;