Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 我有一个问题,我可以';t在组件未装入或函数中获取数据_Reactjs_Function_React Hooks_Fetch - Fatal编程技术网

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())