I've got a very simple function set up to (eventually) load data from
So I guess I have a couple of questions. Is this to be expected? If so, should I be expiring my promises somehow (I haven't found any examples of that yet)? If this isn't to be expected, what am I doing wrong?
CodePudding user response:
Effects need a list of dependencies as their second param.
// Calling poll in the render loop is surely a mistake
// const loadedValuePromise: Promise<any> = poll("some.key");
const updateValue = async () => {
poll("some.key").then((v) => {
setRefreshCount(refreshCount 1);
console.log("then count: " refreshCount);
setValue(v);
});
};
useEffect(() => {
setInterval(() => {
updateValue();
}, 2000);
// An effect with an empty list of dependencies will run once on mount
// and then never again.
}, []);