在“获取贷款”之前,我很难让“studentDataPromise”来解决。我需要获取学生的数据,以便能够获取loans....any的想法,我的错误是什么?
目前
let studentDataPromise = null;
let fetchClassesPromise = null;
let fetchLoansPromise = null;
useEffect(() => {
studentDataPromise = fetchStudentData();
}, []);
useEffect(() => {
fetchClassesPromise = fetchClasses();
}, []);
useEffect(() => {
fetchLoansPromise = fetchLoans();
}, []);
/**
* resolves promises and toggles isReady
* action to true
*/
Promise.all([studentDataPromise, fetchClassesPromise])
.then(() => fetchLoansPromise)
.then(() => toggleIsReady())
.catch(error => {
throw new Error(error);
});发布于 2019-04-12 19:09:20
https://stackoverflow.com/a/55502465/11119825
看这个帖子,这是我现在解决的。感谢大家!
发布于 2019-04-02 19:12:20
如果我理解正确的话,你应该这样做:
const [student, setStudent] = useState({});
const [classes, setClasses] = useState([]);
const [loans, setLoans] = useState([]);
useEffect(async () => {
const studentData = await fetchStudentData();
const fetchClasses = await fetchClasses();
const fetchLoans = await fetchLoans();
await toggleIsReady();
}, []);https://stackoverflow.com/questions/55481796
复制相似问题