You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What you were expecting:
When I switch resource, I get correct list actions with export button
What happened instead:
When I switch resource, export button is missing because the result of ListActions component is memoized
Steps to reproduce:
I have two resource, both has list with export action.
I have a tiny wrapper around ListActions which render export action conditionally according to the user permissions which are loaded asynchronously.
On load I can see export button in resource1
When I switch to resource2 I can also see export button
Switch back on resource1 cause export button to disappear
When I switch to resource2, back button is also missing
Related code:
This is an excerpt from my code:
import{usePermissions}from'react-admin';exportconstuseAppPermissions=()=>usePermissions<RolePermissions>();exportconstuseHasAccess=(resource: ResourceKey, ...askedPermissions: PermissionAction[])=>{const{ permissions }=usePermissions()returnhasAccess(permissions,resource, ...askedPermissions);};/** * ListActions wrapper for conditional rendering of some actions according to the permissions */importtype{ListActionsProps}from'react-admin';exportinterfaceListWithPermissionPropsextendsListActionsProps{}exportconstListActionsWithPermissions=({ filters, exporter, ...props}: ListWithPermissionProps)=>{constresource=useResourceContext()asResourceKey;constaccess={search: useHasAccess(resource,PermissionAction.SEARCH),export: useHasAccess(resource,PermissionAction.EXPORT),};console.log('exporter',access.export ? exporter : false)return(<ListActions{...props}filters={access.search ? filters : undefined}exporter={access.export ? exporter : false}/>);};
Other information
I suppose I've also found the source of the issue. There is a missing exporter dependency in useMemo hook inside ListActions so even when the exporter value changes, the old value is used.
Environment
React-admin version: 3.18.1
React version: 17.0.2
Browser: Chrome
Stack trace (in case of a JS error):
The text was updated successfully, but these errors were encountered:
What you were expecting:
When I switch resource, I get correct list actions with export button
What happened instead:
When I switch resource, export button is missing because the result of
ListActions
component is memoizedSteps to reproduce:
I have two resource, both has list with export action.
I have a tiny wrapper around
ListActions
which render export action conditionally according to the user permissions which are loaded asynchronously.Related code:
This is an excerpt from my code:
Other information
I suppose I've also found the source of the issue. There is a missing
exporter
dependency inuseMemo
hook insideListActions
so even when theexporter
value changes, the old value is used.Environment
The text was updated successfully, but these errors were encountered: