main
Last change
on this file since 299af01 was 057453c, checked in by Naum Shapkarovski <naumshapkarovski@…>, 6 weeks ago |
feat: implement employees
|
-
Property mode
set to
100644
|
File size:
705 bytes
|
Rev | Line | |
---|
[5d6f37a] | 1 | import { useMemo } from 'react';
|
---|
| 2 | // types
|
---|
[057453c] | 3 | import { Service } from 'src/schemas';
|
---|
[5d6f37a] | 4 | // swr
|
---|
| 5 | import useSWR from 'swr';
|
---|
[057453c] | 6 | import { endpoints, fetcher } from 'src/utils/axios';
|
---|
[5d6f37a] | 7 |
|
---|
| 8 | export function useGetServices() {
|
---|
[057453c] | 9 | const { data, isLoading, error, isValidating } = useSWR<Service[]>(
|
---|
| 10 | endpoints.service,
|
---|
| 11 | () => fetcher<Service[]>(endpoints.service),
|
---|
| 12 | {
|
---|
| 13 | revalidateOnFocus: false,
|
---|
| 14 | }
|
---|
| 15 | );
|
---|
[5d6f37a] | 16 |
|
---|
| 17 | const memoizedValue = useMemo(
|
---|
| 18 | () => ({
|
---|
| 19 | services: data || [],
|
---|
| 20 | servicesLoading: isLoading,
|
---|
| 21 | servicesError: error,
|
---|
| 22 | servicesValidating: isValidating,
|
---|
| 23 | servicesEmpty: !isLoading && !data?.length,
|
---|
| 24 | }),
|
---|
| 25 | [data, error, isLoading, isValidating]
|
---|
| 26 | );
|
---|
| 27 |
|
---|
| 28 | return memoizedValue;
|
---|
| 29 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.