Skip to content

react-query-firebase / useEnsureDoc

Function: useEnsureDoc() ​

ts
function useEnsureDoc<AppModelType>(options): UseQueryResult<AppModelType, Error>;

Defined in: src/web/firestore/useEnsureDoc.ts:49

This hook checks if a doc with a requested reference exists. It creates a document with requested data if it does not exist.

Type Parameters ​

AppModelType ​

AppModelType extends AppModel = AppModel

Parameters ​

options ​

object & Omit<{ db: Firestore; path?: string; pathSegments?: string[]; reference?: | CollectionReference<AppModelType, AppModelType> | DocumentReference<AppModelType, AppModelType>; }, "db">

Configuration options for mutation.

Returns ​

UseQueryResult<AppModelType, Error>

A mutation result

Example ​

jsx
export const MyComponent = () => {
 const {data} = useEnsureDocQuery({
     options: {
     },
     reference: collection().doc(),
     defaults: {prop1: 'value1'}
 });

};

Released under the MIT License.