import { OnSuccess, OnFailure } from '../types';
import { DeclarativeSideEffect } from './useDeclarativeSideEffects';
import { DataProviderQuery, Refetch } from './useQueryWithStore';
/**
* Call the data provider on mount
*
* The return value updates according to the request state:
*
* - start: { loading: true, loaded: false, refetch }
* - success: { data: [data from response], total: [total from response], loading: false, loaded: true, refetch }
* - error: { error: [error from response], loading: false, loaded: false, refetch }
*
* @param {Object} query
* @param {string} query.type The method called on the data provider, e.g. 'getList', 'getOne'. Can also be a custom method if the dataProvider supports is.
* @param {string} query.resource A resource name, e.g. 'posts', 'comments'
* @param {Object} query.payload The payload object, e.g; { post_id: 12 }
* @param {Object} options
* @param {string} options.action Redux action type
* @param {boolean} options.enabled Flag to conditionally run the query. True by default. If it's false, the query will not run
* @param {Function} options.onSuccess Side effect function to be executed upon success, e.g. () => refresh()
* @param {Function} options.onFailure Side effect function to be executed upon failure, e.g. (error) => notify(error.message)
* @param {boolean} options.withDeclarativeSideEffectsSupport Set to true to support legacy side effects e.g. { onSuccess: { refresh: true } }
*
* @returns The current request state. Destructure as { data, total, error, loading, loaded, refetch }.
*
* @example
*
* import { useQuery } from '../app';
*
* const UserProfile = ({ record }) => {
* const { data, loading, error } = useQuery({
* type: 'getOne',
* resource: 'users',
* payload: { id: record.id }
* });
* if (loading) { return
ERROR
; } * returnERROR
; } * return ( *Total users: {total}
*