We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cd18182 commit cf4d352Copy full SHA for cf4d352
src/useResource.ts
@@ -112,19 +112,17 @@ export function useResource<T extends Request>(
112
113
const { ready, cancel } = createRequest(...args);
114
115
- void (async () => {
116
- try {
117
- dispatch({ type: "start" });
118
- const [data, response] = await ready();
119
-
+ dispatch({ type: "start" });
+ ready()
+ .then(([data, response]) => {
120
dispatch({ type: "success", data, response });
121
- } catch (e) {
+ })
+ .catch((e) => {
122
const error = e as RequestError<Payload<T>, BodyData<T>>;
123
if (!error.isCancel) {
124
dispatch({ type: "error", error });
125
}
126
- }
127
- })();
+ });
128
129
return cancel;
130
};
0 commit comments