Skip to content

Commit cf4d352

Browse files
committed
refactor(useResource): reduce cognitive complexity
1 parent cd18182 commit cf4d352

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/useResource.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,17 @@ export function useResource<T extends Request>(
112112

113113
const { ready, cancel } = createRequest(...args);
114114

115-
void (async () => {
116-
try {
117-
dispatch({ type: "start" });
118-
const [data, response] = await ready();
119-
115+
dispatch({ type: "start" });
116+
ready()
117+
.then(([data, response]) => {
120118
dispatch({ type: "success", data, response });
121-
} catch (e) {
119+
})
120+
.catch((e) => {
122121
const error = e as RequestError<Payload<T>, BodyData<T>>;
123122
if (!error.isCancel) {
124123
dispatch({ type: "error", error });
125124
}
126-
}
127-
})();
125+
});
128126

129127
return cancel;
130128
};

0 commit comments

Comments
 (0)