i'm wondering how is the best way to get around the Child component being called every time the useState variable is updated. The way I have things currently setup is as follows (stripped down version) -
Parent:
import Child from "../components/child";
import { useState } from "react";
const Home = () => {
return (
<div>
<Child />
</div>
);
};
export default Home;
Child component:
import { useState } from "react";
export default function Child() {
const [count, setCount] = useState(0);
async function fetchData(id) {
while (id < 100) {
console.log(id)
setCount(id)
}
id = id + 1;
}
}
fetchData(10)
return (
<>
{count}
</>
)
}
The parent component gets updated but then calls Child again because of the render and starts it again. how do you stop this kind of behaviour? My "tally" variable is being updated in console no problem but trying to set count to that value rerenders everything causing it to start a second instance of the child component loop