Version: 4.xx.xxSource Code
<CanAccess>
<CanAccess>
is the component form of useCan
.
It internally uses useCan
's return values to provide its functionality.
Passes the given properties to the can
method from your access control provider. After, if it returns:
true
, it renders the children.false
, it rendersfallback
prop if provided. Otherwise, it rendersnull
.
Refer to Access Control Provider for more information. β
Basic Usageβ
import { CanAccess } from "@refinedev/core";
const MyComponent = () => (
<CanAccess
resource="posts"
action="edit"
params={{ id: 1 }}
fallback={<CustomFallback />}
>
<YourComponent />
</CanAccess>
);
Propertiesβ
It's also accepts all the properties of useCan
.
fallback
β
Component to render if useCan
returns false. If undefined
, it renders null
.
<CanAccess fallback={<div>You cannot access this section</div>}>
<YourComponent />
</CanAccess>