Skip to content

Commit

Permalink
controller-typing
Browse files Browse the repository at this point in the history
  • Loading branch information
soullivaneuh committed May 19, 2022
1 parent f9bc5ee commit ee2c728
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions packages/ra-core/src/controller/create/useCreateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ import {
* return <CreateView {...controllerProps} {...props} />;
* }
*/
export const useCreateController = <RecordType extends RaRecord = RaRecord>(
props: CreateControllerProps<RecordType> = {}
export const useCreateController = <
RecordType extends RaRecord = RaRecord,
MutationOptionsError = unknown
>(
props: CreateControllerProps<RecordType, MutationOptionsError> = {}
): CreateControllerResult<RecordType> => {
const {
disableAuthentication,
Expand All @@ -58,11 +61,10 @@ export const useCreateController = <RecordType extends RaRecord = RaRecord>(
const recordToUse = record ?? getRecordFromLocation(location) ?? undefined;
const { onSuccess, onError, ...otherMutationOptions } = mutationOptions;

const [create, { isLoading: saving }] = useCreate<RecordType>(
resource,
undefined,
otherMutationOptions
);
const [create, { isLoading: saving }] = useCreate<
RecordType,
MutationOptionsError
>(resource, undefined, otherMutationOptions);

const save = useCallback(
(
Expand Down
16 changes: 9 additions & 7 deletions packages/ra-core/src/controller/edit/useEditController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ import { SaveHandler } from '../saveContext';
* return <EditView {...controllerProps} {...props} />;
* }
*/
export const useEditController = <RecordType extends RaRecord = any>(
props: EditControllerProps<RecordType> = {}
export const useEditController = <
RecordType extends RaRecord = any,
MutationOptionsError = unknown
>(
props: EditControllerProps<RecordType, MutationOptionsError> = {}
): EditControllerResult<RecordType> => {
const {
disableAuthentication,
Expand Down Expand Up @@ -101,11 +104,10 @@ export const useEditController = <RecordType extends RaRecord = any>(

const recordCached = { id, previousData: record };

const [update, { isLoading: saving }] = useUpdate<RecordType>(
resource,
recordCached,
{ ...otherMutationOptions, mutationMode }
);
const [update, { isLoading: saving }] = useUpdate<
RecordType,
MutationOptionsError
>(resource, recordCached, { ...otherMutationOptions, mutationMode });

const save = useCallback(
(
Expand Down

0 comments on commit ee2c728

Please sign in to comment.