import { QueryObserverLoadingErrorResult, QueryObserverLoadingResult, QueryObserverRefetchErrorResult, QueryObserverSuccessResult, UseQueryOptions } from '@tanstack/react-query'; import { HintedString } from '../types'; /** * A hook that calls the authProvider.canAccess() method using react-query for a provided resource and action (and optionally a record). * * The return value updates according to the request state: * * - start: { isPending: true } * - success: { canAccess: true | false, isPending: false } * - error: { error: [error from provider], isPending: false } * * Useful to enable or disable features based on users permissions. * * @param {Object} params Any params you want to pass to the authProvider * @param {string} params.resource The resource to check access for * @param {string} params.action The action to check access for * @param {Object} params.record Optional. The record to check access for * * @returns Return the react-query result and a canAccess property which is a boolean indicating the access status * * @example * import { useCanAccess } from 'react-admin'; * * const PostDetail = () => { * const { isPending, canAccess, error } = useCanAccess({ * resource: 'posts', * action: 'read', * }); * if (isPending || !canAccess) { * return null; * } * if (error) { * return