diff --git a/README.md b/README.md index df75eed..1be8d70 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ The `useQuery` hook loads query data as soon as the component is mounted. It ret import { useQuery } from "@airstack/airstack-react"; const MyComponent = () => { - const { data, loading, error } = useQuery(query, variables); + const { data, loading, error } = useQuery(query, variables, configAndCallbacks); if (loading) { return

Loading...

; @@ -186,7 +186,8 @@ import { useQueryWithPagination } from "@airstack/airstack-react"; const MyComponent = () => { const { data, loading, pagination } = useQueryWithPagination( query, - variables + variables, + configAndCallbacks ); const { hasNextPage, hasPrevPage, getNextPage, getPrevPage } = pagination; @@ -295,7 +296,8 @@ function App() { ## fetchQuery -fetchQuery can be used in places where using hooks is not possible. `fetchQuery` accepts same parameter as hooks . +fetchQuery can be used in places where using hooks is not possible. `fetchQuery` accepts same parameter as hooks. +**Note**: fetchQuery only accepts config and do not accept callbacks in the third parameter. `fetchQuery` returns a promise with an object, which contains the following properties: diff --git a/package.json b/package.json index e5afb95..da1bfe8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@airstack/airstack-react", - "version": "0.4.8", + "version": "0.4.9", "type": "module", "scripts": { "dev": "vite", diff --git a/src/lib/hooks/useQuery.ts b/src/lib/hooks/useQuery.ts index b6ea1f9..8d4f617 100644 --- a/src/lib/hooks/useQuery.ts +++ b/src/lib/hooks/useQuery.ts @@ -1,6 +1,6 @@ import { useCallback, useEffect } from "react"; import { fetchQuery } from "../apis/fetchQuery"; -import { Config, ConfigAndCallbacks, FetchQueryReturnType, Variables } from "../types"; +import { ConfigAndCallbacks, FetchQueryReturnType, Variables } from "../types"; import { useRequestState } from "./useDataState"; type UseQueryReturnType = { @@ -29,7 +29,7 @@ export function useLazyQuery( variablesRef, setData, setError, - setLoading + setLoading, } = useRequestState(variables, configAndCallbacks); const handleResponse = useCallback( @@ -71,12 +71,12 @@ export function useLazyQuery( export function useQuery( query: string, variables?: Variables, - config?: Config + configAndCallbacks?: ConfigAndCallbacks ): UseQueryReturnType { const [fetch, { data, error, loading }] = useLazyQuery( query, variables, - config + configAndCallbacks ); useEffect(() => { diff --git a/src/lib/hooks/useQueryWithPagination.ts b/src/lib/hooks/useQueryWithPagination.ts index 7fc8752..2794c3b 100644 --- a/src/lib/hooks/useQueryWithPagination.ts +++ b/src/lib/hooks/useQueryWithPagination.ts @@ -1,6 +1,5 @@ import { useState, useRef, useCallback, useEffect, useMemo } from "react"; import { - Config, FetchQuery, FetchPaginatedQueryReturnType, Variables, @@ -49,7 +48,7 @@ export function useLazyQueryWithPagination( variablesRef, setData, setError, - setLoading + setLoading, } = useRequestState(variables, configAndCallbacks); const [hasNextPage, setHasNextPage] = useState(false); const [hasPrevPage, setHasPrevPage] = useState(false); @@ -165,9 +164,13 @@ export function useLazyQueryWithPagination( export function useQueryWithPagination( query: string, variables?: Variables, - config?: Config + configAndCallbacks?: ConfigAndCallbacks ): UseQueryReturnType { - const [fetch, data] = useLazyQueryWithPagination(query, variables, config); + const [fetch, data] = useLazyQueryWithPagination( + query, + variables, + configAndCallbacks + ); useEffect(() => { fetch(); }, [fetch]);