反应钩
我需要在集合之后获取数据,第一个调用总是返回空集合,第二个总是返回传递给它的数据,我需要在第一次调用函数时集合返回返回传递给他们的数据相同的功能。
const [test, setTest] = useState([])
async function array(){
const array = [
{id:1},
{id:2},
{id:3},
]
setTest(array)
console.log("ARRAY TEST",test)//the first call appears as empty the second with the data
}