我只是使用 create-react-app 设置制作一个简单的食谱获取应用程序,但是当我尝试记录响应时,它记录了两次。我倒退并删除代码,直到它停止发生,无论出于何种原因,当我使用状态挂钩时它开始:
import React, { useState } from 'react';
import './App.css';
function App() {
const APP_ID = '092fa53f';
const APP_KEY = '6fcf8c591c129cc3d01aefbda0d8a4d8';
const recipe_url = `https://api.edamam.com/search?q=chicken&app_id=${APP_ID}&app_key=${APP_KEY}`;
const [recipes, setRecipes] = useState(0);
return (
<div className="App">
{console.log('test')}
</div>
);
}
export default App;