Skip to content

Commit

Permalink
Parameterize the type
Browse files Browse the repository at this point in the history
  • Loading branch information
taras committed Jan 20, 2024
1 parent 9a25484 commit 193acaf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/hooks/useLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function useLoader<T>(
retryingMessageInterval = 1000,
} = options;

const [state, setState] = useState<LoaderState<unknown>>({ type: "initial" });
const [state, setState] = useState<LoaderState<T>>({ type: "initial" });
const [key, setKey] = useState<number>(0);

const restart = useCallback(() => {
Expand Down Expand Up @@ -58,7 +58,7 @@ export function useLoader<T>(

useEffect(() => {
const task = run(function* () {
yield* initLoaderStateContext();
yield* initLoaderStateContext<T>();

// eslint-disable-next-line react-hooks/rules-of-hooks
const state = yield* useLoaderState();
Expand Down
6 changes: 3 additions & 3 deletions src/operations/LoaderStateContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { LoaderState } from "../types";
export const LoaderStateContext =
createContext<Channel<LoaderState<unknown>, void>>("loader-state");

export function* initLoaderStateContext() {
const state = yield* resource<Channel<LoaderState<unknown>, void>>(function* (provide) {
const channel = createChannel<LoaderState<unknown>>();
export function* initLoaderStateContext<T>() {
const state = yield* resource<Channel<LoaderState<T>, void>>(function* (provide) {
const channel = createChannel<LoaderState<T>>();

try {
yield* provide(channel);
Expand Down

0 comments on commit 193acaf

Please sign in to comment.