still learning react a bit and am trying to understand the rendering process... I felt like I had a decent grasp until this current project.
import { useEffect, useState } from "react";
import BazaarPage from "./Components/BazaarPage";
import "./styles.css";
export default function App() {
const [data, setData] = useState();
useEffect(() => {
async function getData() {
fetch("https://api.slothpixel.me/api/skyblock/bazaar")
.then((data) => data.json())
.then((obj) => {
setData(obj);
});
}
getData();
}, []);
return <div className="App">{data && <BazaarPage data={data} />}</div>;
}
export default function BazaarPage({ data }) {
console.log(data);
return <div className="bazzar-page"></div>;
}
This, I would expect, would console.log 1 time... But it renders 4 times...
My thought process being that my "BazaarPage" component wouldn't render until there is something in the "data" state based on the data && <BazaarPage data={data} /> conditional. I also understand it that the "App" component should render twice, once on initial run of the page and a second time when the state gets updated in my setData in the the useEffect.
Why is this logging the data 4 times and where is my understanding incorrect?