Skip to content

Commit

Permalink
(feat) Added type passing in the useOpenmrsSwr (#891)
Browse files Browse the repository at this point in the history
* Added type passing in the OpenMRS SWR Fetch

* Improved Data and Error types
  • Loading branch information
vasharma05 authored Jan 17, 2024
1 parent c07c4f8 commit dbcfd10
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/framework/esm-react-utils/src/useOpenmrsSWR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useCallback, useMemo } from 'react';
import type { SWRConfiguration } from 'swr';
import useSWR from 'swr';
import { type FetchConfig, openmrsFetch } from '@openmrs/esm-api';
import { type FetchConfig, openmrsFetch, type FetchResponse } from '@openmrs/esm-api';
import useAbortController from './useAbortController';

export type ArgumentsTuple = [any, ...unknown[]];
Expand Down Expand Up @@ -67,7 +67,7 @@ function getUrl(key: Key, url?: string | ((key: Key) => string)): string {
* @param options An object of optional parameters to provide, including a {@link FetchConfig} object
* to pass to {@link openmrsFetch} or options to pass to SWR
*/
export function useOpenmrsSWR(key: Key, options: UseOpenmrsSWROptions = {}) {
export function useOpenmrsSWR<DataType = any, ErrorType = any>(key: Key, options: UseOpenmrsSWROptions = {}) {
const { abortController, fetchInit, url, swrConfig } = options;
const ac = useAbortController();
const abortSignal = useMemo<AbortSignal>(
Expand All @@ -83,5 +83,5 @@ export function useOpenmrsSWR(key: Key, options: UseOpenmrsSWROptions = {}) {
[abortSignal, fetchInit, url],
);

return useSWR(key, fetcher, swrConfig);
return useSWR<FetchResponse<DataType>, ErrorType>(key, fetcher, swrConfig);
}

0 comments on commit dbcfd10

Please sign in to comment.