Skip to content

Instantly share code, notes, and snippets.

@morintd
Last active March 11, 2024 20:21
Show Gist options
  • Save morintd/eb469922e5400a967223e37013f3c29f to your computer and use it in GitHub Desktop.
Save morintd/eb469922e5400a967223e37013f3c29f to your computer and use it in GitHub Desktop.
import { useQuery } from "@tanstack/react-query";
import { useDependencyContext } from "../common/dependency-context";
import { useMemo } from "react";
import { GameDomainModel } from "./game.domain-model";
import { Initialize } from "./use-cases/initialize.use-case";
export function useInitializeQuery() {
const dependencies = useDependencyContext();
const initialize = useMemo(() => {
return new Initialize(dependencies.board);
}, [dependencies.board]);
const query = useQuery<GameDomainModel.GameState>({
queryKey: ["initialize"],
queryFn: () => initialize.execute(),
});
return {
data: query.data,
error: query.error,
isPending: query.isPending,
isError: query.isError,
isSuccess: query.isSuccess,
};
}
export function useHomeController() {
const initialize = useInitializeQuery();
return {
initialize,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment