({
key,
defaultValue,
}: UseQueryStateProps<T>)
| 23 | } |
| 24 | |
| 25 | export const useQueryState = <T>({ |
| 26 | key, |
| 27 | defaultValue, |
| 28 | }: UseQueryStateProps<T>): UseQueryState<T> => { |
| 29 | const client = useQueryClient(); |
| 30 | const { data = defaultValue, ...rest } = useQuery<T>({ |
| 31 | queryKey: key, |
| 32 | queryFn: () => client.getQueryData<T>(key) ?? defaultValue, |
| 33 | ...disabledRefetch, |
| 34 | initialData: defaultValue, |
| 35 | staleTime: Infinity, |
| 36 | }); |
| 37 | const setState = useCallback( |
| 38 | (value: T) => client.setQueryData<T>(key, value), |
| 39 | [client, key], |
| 40 | ); |
| 41 | |
| 42 | return [data, setState, rest]; |
| 43 | }; |
no outgoing calls
no test coverage detected