alibaba / hooks

A high-quality & reliable React Hooks library. https://ahooks.pages.dev/
https://ahooks.js.org/
MIT License
14.02k stars 2.71k forks source link

【RFC】useRequest support Suspense Mode #475

Open jeasonstudio opened 4 years ago

jeasonstudio commented 4 years ago

API

export type BaseOptions<R, P extends any[]> = {
  // ...
  // Enable React Suspense mode, default false.
  suspense?: boolean;
  // ...
};

// ...
function useRequest<R, P extends any[]>(
  service: Service<P>,
  options?: BaseOptions<R, P>,
): BaseResult<R, P>;

Suspense do not support SSR mode.

DEMO

import React, { Suspense } from 'react';
import { useRequest } from 'ahooks';

function Profile() {
  const { data } = useRequest(service, { suspense: true });
  return <div>hello, {data.name}</div>;
}

function App() {
  return (
    <Suspense fallback={<div>loading...</div>}>
      <Profile />
    </Suspense>
  );
}

Implement

TODO

SunStupic commented 2 years ago

What's the status of this task?

brickspert commented 2 years ago

What's the status of this task?

The current version does not support suspense, we will support it later when Suspense is stable.

devnomic commented 2 years ago

What's the status of this task?

The current version does not support suspense, we will support it later when Suspense is stable.

I hope it's the time to support it as react 18 already out.

brickspert commented 2 years ago

What's the status of this task?

The current version does not support suspense, we will support it later when Suspense is stable.

I hope it's the time to support it as react 18 already out.

I will work for it.

zhemuse commented 2 weeks ago

What's the status of this task?

The current version does not support suspense, we will support it later when Suspense is stable.

I hope it's the time to support it as react 18 already out.

I will work for it.

It’s 2024. Isn’t it still supported?