hooks [useRequest] loading first time state always return true when use ready and set loadingDelay values in options

wmvff8tz  于 2022-10-25  发布在  其他
关注(0)|答案(1)|浏览(225)

look :
Example code of using the ahooks website

export default () => {
  const [ready, { toggle }] = useToggle(false);

  const { data, loading } = useRequest(getUsername, {
    ready,
    loadingDelay: 300,
  });

  return (
    <>
      <p>
        Ready: {JSON.stringify(ready)}
        <button onClick={toggle} style={{ marginLeft: 16 }}>
          Toggle Ready
        </button>
      </p>
      <p>Username: {loading ? 'Loading' : data}</p>
    </>
  );
};

相关问题