如何从反应中的变量中的获取调用访问值

How to access value from fetch call in a variable in react

如何在react的Fetch调用中给变量赋值。 因为我在 JS 中使用 map 一个接一个地调用了 2 API 面临如何从另一个函数访问数据的问题

var data = ""
fetch(url,{})
.then((res)=> res.json())
.then((output) => data = output)
 const numberOfProject = (project_id,callback) => {
        var numprj;
        fetch(accountUrl,{
            method:"POST",
            headers: {
                'Accept':'application/json',
                'Content-Type':'application/json'
            },
            body:JSON.stringify({"project_id": project_id})
        })
        .then((res) => res.json())
        .then((data) => numprj = data)
        .then(() => callback(numprj))
    }

现在用回调调用函数

numberOfProject(item.project_id, getData)

现在在getData中,我们将接收数据

const getData = (response) => {
                    projNum = response
                    console.log(">>>>>>>>>>>>>>>2",projNum)
                }