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