diff --git a/packages/core-data/README.md b/packages/core-data/README.md index 471d91f0125669..de28e4b86be4bf 100644 --- a/packages/core-data/README.md +++ b/packages/core-data/README.md @@ -1230,7 +1230,7 @@ the store state using `canUser()`, or resolved if missing. _Parameters_ - _resource_ `string | EntityResource`: Entity resource to check. Accepts entity object `{ kind: 'root', name: 'media', id: 1 }` or REST base as a string - `media`. -- _id_ `IdType`: Optional ID of the resource to check, e.g. 10. Note: The argument will be ignored when using an entity object as a resource to check permissions. +- _id_ `IdType`: Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged when using an entity object as a resource to check permissions and will be ignored. _Returns_ diff --git a/packages/core-data/src/hooks/use-resource-permissions.ts b/packages/core-data/src/hooks/use-resource-permissions.ts index 332e4da1fb615d..38dfc1ed77a3e6 100644 --- a/packages/core-data/src/hooks/use-resource-permissions.ts +++ b/packages/core-data/src/hooks/use-resource-permissions.ts @@ -61,8 +61,8 @@ function useResourcePermissions< IdType = void >( * * @param resource Entity resource to check. Accepts entity object `{ kind: 'root', name: 'media', id: 1 }` * or REST base as a string - `media`. - * @param id Optional ID of the resource to check, e.g. 10. Note: The argument will be ignored - * when using an entity object as a resource to check permissions. + * @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged + * when using an entity object as a resource to check permissions and will be ignored. * * @example * ```js @@ -132,10 +132,9 @@ function useResourcePermissions< IdType = void >( // We can't just pass `resource` as one of the deps, because if it is passed // as an object literal, then it will be a different object on each call even // if the values remain the same. - const resourceAsString = - typeof resource === 'object' ? JSON.stringify( resource ) : resource; - const isEntity = typeof resource === 'object'; + const resourceAsString = isEntity ? JSON.stringify( resource ) : resource; + if ( isEntity && typeof id !== 'undefined' ) { warning( `When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`