Answer the question
In order to leave comments, you need to log in
Why is the component not updated after import?
I have react component
MyAccount.jsx
import "./myAccount.sass";
function MyAccount() {
return (
<div className="MyAccount">
<h3 className="MyAccount_title">Hi, *USERNAME*</h3>
<div className="MyAccount_logout-container">
<button className="MyAccount_logout">Logout...</button>
</div>
<hr className="MyAccount_hr" />
<h4 className="MyAccount_subtitle">Your reviews:</h4>
</div>
);
}
export default MyAccount;
import { useState, useEffect } from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import {
collection,
getDocs,
} from "https://www.gstatic.com/firebasejs/9.6.0/firebase-firestore.js";
import { onAuthStateChanged } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-auth.js";
import { db, auth } from "../firebaseConfig";
import Hotels from "./Hotels/Hotels";
import CreateReview from "./CreateReview/CreateReview";
import MyAccount from "./MyAccount/MyAccount";
import WelcomePage from "./WelcomePage/WelcomePage";
import NavBar from "./NavBar/NavBar";
function MainPage() {
const [hotels, setHotels] = useState([]);
const [authentication, setAuthentication] = useState(false);
async function fetchHotels() {
const _hotels = [];
const querySnapshot = await getDocs(collection(db, "reviews"));
querySnapshot.forEach((doc) => {
_hotels.push(doc.data());
});
console.log("Data is fetched!");
setHotels(_hotels);
}
useEffect(() => {
fetchHotels();
}, []);
function isAuthenticated() {
onAuthStateChanged(auth, (user) => {
if (user) {
setAuthentication(true);
console.log("User is signed in");
} else {
setAuthentication(false);
console.log("User is signed out");
}
});
}
useEffect(() => {
isAuthenticated();
}, []);
return (
<div>
{authentication ? (
<BrowserRouter>
<NavBar />
<div className="container">
<Routes>
<Route
exact
path="/CreateReview"
element={<CreateReview />}
></Route>
<Route
index
exact
path="/Hotels"
element={<Hotels hotels={hotels} />}
></Route>
<Route
exact
path="/MyAccount"
element={<MyAccount sraka={setAuthentication} />}
></Route>
<Route path="*" element={<Hotels hotels={hotels} />} />
</Routes>
</div>
</BrowserRouter>
) : (
<div className="container">
<WelcomePage />
</div>
)}
</div>
);
}
export default MainPage;
import {
collection,
getDocs,
} from "https://www.gstatic.com/firebasejs/9.6.0/firebase-firestore.js";
import { onAuthStateChanged } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-auth.js";
import { db, auth } from "../../firebaseConfig";
import "./myAccount.sass";
function MyAccount() {
return (
<div className="MyAccount">
<h3 className="MyAccount_title">Hi, *USERNAME*</h3>
<div className="MyAccount_logout-container">
<button className="MyAccount_logout">Logout...</button>
</div>
<hr className="MyAccount_hr" />
<h4 className="MyAccount_subtitle">Your reviews:</h4>
</div>
);
}
export default MyAccount;
import {
collection,
getDocs,
} from "https://www.gstatic.com/firebasejs/9.6.0/firebase-firestore.js";
import { onAuthStateChanged } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-auth.js";
import { db, auth } from "../../firebaseConfig";
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question