react-hooks icon indicating copy to clipboard operation
react-hooks copied to clipboard

Expose `request` in result of `useRequest` as well

Open 599316527 opened this issue 3 years ago • 2 comments

https://github.com/ecomfe/react-hooks/blob/8d89a72ea22b6591b9cb226e8378e8ba7cc1e1c2/packages/request/src/index.ts#L163-L166

Expacted:

 const resultFixedForEffect = {
      ...result,
      pending: result.pendingCount === undefined ? true : result.pending,
+     request,
 };

So that I can trigger request automatically as well as manually.

const {pending, data: tasks, request: reload} = useRequest(getTasks, {status});
return <>
   <button onClick={reload}>Refresh</button>
   <List loading={pending} items={tasks} />
</>;

599316527 avatar Aug 05 '21 13:08 599316527

Seems reasonable, however this request function should be named refresh?

otakustay avatar Aug 07 '21 13:08 otakustay

Yes! refresh or reload are all acceptable.

599316527 avatar Aug 09 '21 04:08 599316527