Skip to content

Commit 1647909

Browse files
authored
Merge pull request #5863 from marmelab/Fix-List-outside-of-recourcecontext
Fix error when using <List> outside of a ResourceContext
2 parents bb986ab + a38ad80 commit 1647909

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/ra-core/src/controller/useListController.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface ListControllerProps<RecordType extends Record = Record> {
109109
const useListController = <RecordType extends Record = Record>(
110110
props: ListProps
111111
): ListControllerProps<RecordType> => {
112-
useCheckMinimumRequiredProps('List', ['basePath', 'resource'], props);
112+
useCheckMinimumRequiredProps('List', ['basePath'], props);
113113

114114
const {
115115
basePath,
@@ -124,6 +124,11 @@ const useListController = <RecordType extends Record = Record>(
124124
} = props;
125125
const resource = useResourceContext(props);
126126

127+
if (!resource) {
128+
throw new Error(
129+
`<List> was called outside of a ResourceContext and without a resource prop. You must set the resource prop.`
130+
);
131+
}
127132
if (filter && isValidElement(filter)) {
128133
throw new Error(
129134
'<List> received a React element as `filter` props. If you intended to set the list filter elements, use the `filters` (with an s) prop instead. The `filter` prop is internal and should not be set by the developer.'

0 commit comments

Comments
 (0)