"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const react = require("react");
const useJsonMemo = (value) => {
  const json = react.useMemo(() => JSON.stringify(value), [value]);
  return react.useMemo(() => value, [json]);
};
const useQuery = (client, query, variables, apiToken) => {
  const [state, setState] = react.useState({
    state: "loading"
  });
  const vars = useJsonMemo(variables);
  const refetch = react.useCallback(async () => {
    setState({ state: "loading" });
    try {
      const response = await client.sendRequest(query, {
        variables: vars,
        apiTokenOverride: apiToken
      });
      setState({
        ...response,
        state: "success"
      });
    } catch (e) {
      setState({ state: "error", error: e });
    }
  }, [client, query, vars, apiToken]);
  react.useEffect(() => {
    refetch();
  }, [refetch]);
  return react.useMemo(() => ({ state, refetch }), [state, refetch]);
};
exports.useQuery = useQuery;
//# sourceMappingURL=useQuery.cjs.map
