[英]How delay redux saga action to store data update?
Can't delay action firing (initialize from redux-form) to store data update after fetching. 无法延迟操作触发(从redux-form初始化)来存储获取后的数据更新。
const {getAccount, initialize} = props
prepareData = () => {...prepared obj}
useEffect(() => {
const begin = async () => {
await getAccount();
await initialize(prepareData());
};
begin();
}, [account.id]);
main aim to avoid unnecessary second request 主要目的是避免不必要的第二次请求
What if you put a conditional on the begin
call? 如果您将条件作为begin
通话怎么办?
const {getAccount, initialize} = props
const {begun, setBegun} = useState(false)
prepareData = () => {...prepared obj}
useEffect(() => {
const begin = async () => {
await setBegun(true);
await getAccount();
await initialize(prepareData());
};
begun || begin();
}, [account.id]);
Should getAccount
be called if account.id
doesn't exist? 如果account.id
不存在,应该调用getAccount
吗? If not then simply check that account.id
exists before calling begin. 如果没有,那么只需在调用begin之前检查account.id
存在。
const {getAccount, initialize} = props
prepareData = () => {...prepared obj}
useEffect(() => {
// add a guard condition to exit early if account.id doesn't exist yet
if (!account.id) {
return;
}
const begin = async () => {
await getAccount();
await initialize(prepareData());
};
begin();
}, [account.id]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.