Skip to content

react-query-firebase / web/firestore / useAddDocMutation

Function: useAddDocMutation()

ts
function useAddDocMutation<AppModelType, TContext>(options): UseMutationResult<AppModelType, FirebaseError, {
  data: WithFieldValue<AppModelType>;
}, TContext>;

Defined in: web/firestore/useAddDocMutation.ts:59

Executes a mutation and returns added document

Type Parameters

AppModelType

AppModelType extends AppModel = AppModel

TContext

TContext = unknown

Parameters

options

Configuration options for the mutation.

collectionReference

CollectionReference<AppModelType, AppModelType>

Reference to a collection where document must be added

options?

Omit<UseMutationOptions<AppModelType, FirebaseError, { data: WithFieldValue<AppModelType>; }, TContext>, "mutationFn"> = {}

Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.

Returns

UseMutationResult<AppModelType, FirebaseError, { data: WithFieldValue<AppModelType>; }, TContext>

A mutation result

Example

jsx
export const MyComponent = () => {
 const {mutate} = useAddDocMutation({
     options: {
     },
     reference: collection(),
 });

 // ....
 mutate({data: {test: 'value'}});
 // ....
};

Released under the MIT License.