Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/firestore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function useFirestoreDocData<T = unknown>(ref: DocumentReference<T>, opti
const idField = options ? checkIdField(options) : 'NO_ID_FIELD';

const observableId = `firestore:docData:${ref.firestore.app.name}:${ref.path}:idField=${idField}`;
const observable = docData(ref, { idField });
const observable = docData(ref, { idField: idField as keyof T });

return useObservable(observableId, observable, options) as ObservableStatus<T>;
}
Expand All @@ -75,7 +75,7 @@ export function useFirestoreDocDataOnce<T = unknown>(ref: DocumentReference<T>,
const idField = options ? checkIdField(options) : 'NO_ID_FIELD';

const observableId = `firestore:docDataOnce:${ref.firestore.app.name}:${ref.path}:idField=${idField}`;
const observable$ = docData(ref, { idField }).pipe(first());
const observable$ = docData(ref, { idField: idField as keyof T }).pipe(first());

return useObservable(observableId, observable$, options) as ObservableStatus<T>;
}
Expand All @@ -96,7 +96,7 @@ export function useFirestoreCollection<T = DocumentData>(query: FirestoreQuery<T
export function useFirestoreCollectionData<T = DocumentData>(query: FirestoreQuery<T>, options?: ReactFireOptions<T[]>): ObservableStatus<T[]> {
const idField = options ? checkIdField(options) : 'NO_ID_FIELD';
const observableId = `firestore:collectionData:${getUniqueIdForFirestoreQuery(query)}:idField=${idField}`;
const observable$ = collectionData(query, { idField });
const observable$ = collectionData(query, { idField: idField as (string & keyof T) });

return useObservable(observableId, observable$, options);
}
12 changes: 4 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export class ReactFireError extends Error {

export interface ReactFireOptions<T = unknown> {
idField?: string;
initialData?: T | any;
initialData?: T;
/**
* @deprecated use initialData instead
*/
startWithValue?: T | any;
startWithValue?: T;
suspense?: boolean;
}

Expand All @@ -40,12 +40,8 @@ export function checkOptions(options: ReactFireOptions, field: string) {
throw new Error(`Field "${field}" is not a valid key in ReactFireOptions`);
}

export function checkinitialData(options: ReactFireOptions) {
return checkOptions(options, 'initialData');
}

export function checkIdField(options: ReactFireOptions) {
return checkOptions(options, 'idField');
export function checkIdField(options: ReactFireOptions): string | undefined {
return options?.idField;
}

export * from './auth';
Expand Down
2 changes: 1 addition & 1 deletion src/useObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function useObservable<T = unknown>(observableId: string, source: Observa

// modify the value if initialData exists
if (!observable.hasValue && hasData) {
update.data = config?.initialData ?? config?.startWithValue;
update.data = (config?.initialData ?? config?.startWithValue) as T | undefined;
update.status = 'success';
update.hasEmitted = true;
}
Expand Down