-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f77d0e8
commit 004aea7
Showing
11 changed files
with
138 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import axios, { AxiosResponse, AxiosError } from 'axios'; | ||
import useSWR from 'swr'; | ||
|
||
/** | ||
* Fetcher function | ||
*/ | ||
export const fetcher = <T>(endpoint: string) => | ||
axios.get(endpoint).then((res: AxiosResponse<T>) => res.data); | ||
|
||
/** | ||
* useEmpathy props | ||
*/ | ||
export type UseEmpathyProps = string; | ||
|
||
/** | ||
* useEmpathy return type | ||
*/ | ||
export type UseEmpathyType<T> = { | ||
data: T | undefined; | ||
error: any | undefined; | ||
isLoading: boolean; | ||
}; | ||
|
||
/** | ||
* useEmpathy hook | ||
*/ | ||
export const useEmpathy = <T>(endpoint: UseEmpathyProps): UseEmpathyType<T> => { | ||
const { data, error } = useSWR<T, AxiosError>(endpoint, fetcher); | ||
|
||
if (error) { | ||
console.warn(`Error fetching "${endpoint}": `, { error }); | ||
console.error(error); | ||
} | ||
|
||
return { | ||
data, | ||
error, | ||
isLoading: !error && !data, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,2 @@ | ||
export { ExampleComponent } from './components/example'; | ||
export type { ExampleComponentProps } from './components/example'; | ||
|
||
export { useExampleHook } from './hooks/example'; | ||
export type { ExampleHookType } from './hooks/example'; | ||
|
||
export { ExampleContext, useExampleContext } from './contexts/example'; | ||
export type { ExampleContextType } from './contexts/example'; | ||
|
||
export { ExampleProvider } from './providers/example'; | ||
export type { ExampleProviderProps } from './providers/example'; | ||
export { fetcher, useEmpathy } from './hooks/useEmpathy'; | ||
export type { UseEmpathyProps, UseEmpathyType } from './hooks/useEmpathy'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters