我已經設定了一個非常簡單的函式來(最終)從
所以我想我有幾個問題。這是意料之中的嗎?如果是這樣,我是否應該以某種方式使我的承諾到期(我還沒有找到任何例子)?如果這不是預期的,我做錯了什么?
uj5u.com熱心網友回復:
Effects 需要一個依賴項串列作為它們的第二個引數。
// 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.
}, []);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/328244.html
上一篇:useStateArray布爾切換-ReactNative
下一篇:反應識別控制或按下Shift鍵
