react-hooks
react-hooks copied to clipboard
Expose `request` in result of `useRequest` as well
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} />
</>;
Seems reasonable, however this request
function should be named refresh
?
Yes! refresh
or reload
are all acceptable.