Skip to content

Commit

Permalink
Throw an error when useGetOne is called for an undefined resource
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Feb 19, 2020
1 parent 09785b9 commit 3844196
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/ra-core/src/dataProvider/useGetOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ const useGetOne = (
useQueryWithStore(
{ type: 'getOne', resource, payload: { id } },
options,
(state: ReduxState) =>
state.admin.resources[resource]
? state.admin.resources[resource].data[id]
: null
(state: ReduxState) => {
if (!state.admin.resources[resource]) {
throw new Error(
`No <Resource> defined for "${resource}". useGetOne() relies on the Redux store, so it cannot work if you don't include a <Resource>.`
);
}
return state.admin.resources[resource].data[id];
}
);

export type UseGetOneHookValue = {
Expand Down

0 comments on commit 3844196

Please sign in to comment.