Reactjs 我有一个问题,我可以';t在组件未装入或函数中获取数据
我想从我所在州的电影数据库中获取数据,我尝试使用钩子,但我做不到,现在这个州也有同样的问题Reactjs 我有一个问题,我可以';t在组件未装入或函数中获取数据,reactjs,function,react-hooks,fetch,Reactjs,Function,React Hooks,Fetch,我想从我所在州的电影数据库中获取数据,我尝试使用钩子,但我做不到,现在这个州也有同样的问题 componentDidMount() { fetch(jsonUrl) .then(response => { response.json(); }) .then( data => { console.log("CDM", data); }); } 当我尝试在Compo
componentDidMount() {
fetch(jsonUrl)
.then(response => {
response.json();
})
.then( data => {
console.log("CDM", data);
});
}
当我尝试在ComponentDidMount内部、函数内部或useEffect挂钩内部获取时,它不会返回任何内容,只返回未定义的内容
我想要数据,请帮助我
非常感谢我看到一个回调问题
.then(response => {
response.json();
// No explicit return then this function will return undefined
})
应该是
.then(response => {
return response.json(); // this returns whatever returned from response.json()
})
或
.then(response => response.json())