我使用useFetch同时发送2个请求,在Safari上,响应变得混合
const [entries,setEntries] = useState([]);
const [categories,setCategories] = useState([]);
const { get, response} = useFetch('https://api.publicapis.org');
const getData = useCallback( async()=>{
const entriesRes = await get('/entries?category=animals&https=true')
if(response.ok)
setEntries(entriesRes.entries)
},[])
const getCategories = useCallback( async()=>{
const categoriesRes = await get('/categories')
if(response.ok)
setCategories(categoriesRes)
},[])
useEffect(()=>{
getData();
getCategories();
},[])
如果getCategories首先返回,则响应转到entriesRes,而不是categoriesRes,这种情况仅在safari中发生
1条答案
按热度按时间k97glaaz1#
尝试重命名useFetch结果: