我有一个从API提取json的函数
function getTravelsFromApi(
URL,
setDeparture,
...
) {
return fetch(URL)
.then(response => response.json())
.then((json) => {
setDeparture(json.from);
...
})
}
setDeparture
是从以下useState
钩子返回的
const [departure, setDeparture] = useState({});
该函数正在传递给useEffect
钩子
useEffect(() => {
getTravelsFromApi(URL, setDeparture, ...);
}, []);
调用getTravelsFromApi
时会引发以下错误:
TypeError: setDeparture is not a function. (In 'setDeparture(...)', 'setDeparture' is undefined