Skip to content

Commit 38ac43d

Browse files
committed
Add documentation for permission reloading
1 parent 3aac93f commit 38ac43d

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

docs/usePermissions.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,32 @@ const MyPage = () => {
6161
}
6262
```
6363

64+
## Refreshing permissions
65+
66+
Permissions are loaded on page load and cached. If your application requires permissions to be refreshed, for example after a change modifying user permissions, you can use `refetch` function to trigger reload.
67+
68+
```jsx
69+
const GrantAdminPermissionsButton = () => {
70+
const record = useRecordContext();
71+
const [ update ] = useUpdate();
72+
const { refetch } = usePermissions();
73+
74+
const handleClick = () => {
75+
update(
76+
"users",
77+
{ id: record.id, data: { admin: true }, previousData: record },
78+
);
79+
refetch();
80+
}
81+
82+
return (
83+
<Button onClick={handleClick}>
84+
Make user an admin
85+
</Button>
86+
)
87+
}
88+
```
89+
6490
## RBAC
6591

6692
[The ra-rbac module](https://marmelab.com/ra-enterprise/modules/ra-rbac)<img class="icon" src="./img/premium.svg" /> provides an alternative implementation of the `usePermissions` hook. It returns an array of permissions, resulting in the merge of the user permissions and the permissions from the user roles.

0 commit comments

Comments
 (0)