Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ad2d85d

Browse files
error and success fn
1 parent 1ad7c1e commit ad2d85d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

‎package.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "react-api-call",
3-
"version": "1.0.6",
3+
"version": "1.0.8",
44
"type": "module",
55
"description": "This is an npm to manage your all of api calls",
6-
"main": "dist/index.js",
6+
"main": "dist/index",
7+
"types": "dist/index",
78
"scripts": {
89
"build:dev": "rollup -c --environment NODE_ENV:development",
910
"build": "rollup -c --environment NODE_ENV:production"

‎src/hooks/useSubmitMethod.js‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ const useSubmitMethod = ({
1010
const [response, setResponse] = useState(null);
1111
const [error, setError] = useState(null);
1212

13-
const handleSubmit = async ({ url, data, method = "POST", onSuccess }) => {
13+
const handleSubmit = async ({
14+
url,
15+
data,
16+
method = "POST",
17+
onSuccess,
18+
onError,
19+
}) => {
1420
setIsLoading(true);
1521
setResponse(null);
1622
setError(null);
@@ -44,9 +50,15 @@ const useSubmitMethod = ({
4450
} else {
4551
const errorResponse = res || "Request failed";
4652
setError(errorResponse);
53+
if (onError && typeof onError === "function") {
54+
onError(errorResponse);
55+
}
4756
}
4857
} catch (err) {
4958
setError(err.response || "Request failed");
59+
if (onError && typeof onError === "function") {
60+
onError(errorResponse);
61+
}
5062
} finally {
5163
setIsLoading(false);
5264
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /