@hyper-fetch/react
Version:
React hooks and utils for the hyper-fetch
28 lines (24 loc) • 777 B
text/typescript
import type { RequestInstance } from "@hyper-fetch/core";
import { renderHook } from "@testing-library/react";
import type { UseTrackedStateProps } from "helpers";
import { useTrackedState } from "helpers";
import { isEqual } from "utils";
export const renderUseTrackedState = <Request extends RequestInstance>(
request: Request,
options?: Partial<UseTrackedStateProps<Request>>,
) => {
const { client } = request;
const { fetchDispatcher: dispatcher, loggerManager } = client;
const logger = loggerManager.initialize(client, "test");
return renderHook(() => {
return useTrackedState({
logger,
request,
dispatcher,
initialResponse: null,
deepCompare: isEqual,
dependencyTracking: false,
...options,
});
});
};