ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
39 lines • 1.61 kB
TypeScript
import { UseQueryOptions } from 'react-query';
/**
* Hook for getting user permissions
*
* Calls the authProvider.getPermissions() method using react-query.
* If the authProvider returns a rejected promise, returns empty permissions.
*
* The return value updates according to the request state:
*
* - start: { isLoading: true }
* - success: { permissions: [any], isLoading: false }
* - error: { error: [error from provider], isLoading: false }
*
* Useful to enable features based on user permissions
*
* @param {Object} params Any params you want to pass to the authProvider
*
* @returns The current auth check state. Destructure as { permissions, error, isLoading, refetch }.
*
* @example
* import { usePermissions } from 'react-admin';
*
* const PostDetail = props => {
* const { isLoading, permissions } = usePermissions();
* if (!isLoading && permissions == 'editor') {
* return <PostEdit {...props} />
* } else {
* return <PostShow {...props} />
* }
* };
*/
declare const usePermissions: <Permissions_1 = any, Error_1 = any>(params?: {}, queryParams?: UseQueryOptions<Permissions_1, Error_1, Permissions_1, import("react-query").QueryKey>) => {
permissions: Permissions_1;
isLoading: boolean;
error: Error_1;
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<Permissions_1, Error_1>>;
};
export default usePermissions;
//# sourceMappingURL=usePermissions.d.ts.map