Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2021
Kelas D
PT Gizi Sehat - Dietela
Dietela Mobile
Commits
bbd2bbfa
Commit
bbd2bbfa
authored
May 11, 2021
by
wulanmantiri
Browse files
[REFACTOR] Modify logic for useApi hooks to minimize render
parent
62921390
Pipeline
#76384
passed with stages
in 26 minutes and 50 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/hooks/useApi/index.ts
View file @
bbd2bbfa
...
...
@@ -8,16 +8,14 @@ const useApi = <T>(
):
{
isLoading
:
boolean
;
}
&
Response
<
T
>
=>
{
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
);
const
[
response
,
setResponse
]
=
useState
({
isLoading
:
true
,
success
:
false
,
});
useEffect
(()
=>
{
const
fetchData
=
async
()
=>
{
setIsLoading
(
true
);
const
apiResponse
=
await
fetchApi
();
setResponse
(
apiResponse
);
if
(
!
apiResponse
.
success
)
{
Toast
.
show
({
type
:
'
error
'
,
...
...
@@ -25,16 +23,16 @@ const useApi = <T>(
text2
:
'
Terjadi kesalahan pada sisi kami.
'
,
});
}
setIsLoading
(
false
);
setResponse
({
isLoading
:
false
,
...
apiResponse
,
});
};
fetchData
();
},
[
fetchApi
]);
return
{
isLoading
,
...
response
,
};
return
response
;
};
export
default
useApi
;
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment