📌  相关文章
📜  在 useEffect 中使用异步函数 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:06.009000             🧑  作者: Mango

代码示例4
function OutsideUsageExample() {
  const [data, dataSet] = useState(null)

  const fetchMyAPI = useCallback(async () => {
    let response = await fetch('api/data')
    response = await response.json()
    dataSet(response)
  }, [])

  useEffect(() => {
    fetchMyAPI()
  }, [fetchMyAPI])

  return (
    
data: {JSON.stringify(data)}
) }