跳到主要内容

useRequest

语法


import React from "react";
import { useRequest } from "ahooks";

function App() {
const getName = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("柏拉文");
}, 1000);
});
};

const { data, loading } = useRequest(getName);
return <div>{loading ? <div>加载中</div> : <div>{data}</div>}</div>;
}

export default App;

实现