Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

reactjs - Pass in firebase config to reduxFirestore typescript. TypeError: firestore.collection is not a function

When I create the store and pass in my firebase config to reduxFirestore, I get a compilation error.

const store = createStore(rootReducer,
  compose(
    applyMiddleware(thunk.withExtraArgument({ getFirestore })),
    reduxFirestore(firebase, firebaseConfig) // compilation error here
  )
);

When I check the type of the argument otherConfig?: Partial<Config>, it has nothing to do with the firebase params config type.

Config type from the redux-firestore index.d.ts (comments in code removed)

export interface Config {
  enableLogging: boolean;
  helpersNamespace: string | null;
  logListenerError: boolean;
  enhancerNamespace: string;
  allowMultipleListeners:
    | ((listenerToAttach: any, currentListeners: any) => boolean)
    | boolean;
  preserveOnDelete: null | object;
  preserveOnListenerError: null | object;
  onAttemptCollectionDelete:
    | null
    | ((queryOption: string, dispatch: Dispatch, firebase: Object) => void);
  mergeOrdered: boolean;
  mergeOrderedDocUpdate: boolean;
  mergeOrderedCollectionUpdates: boolean;
}

The expected type to pass the firebase config in would be one that fits the firebase config object:

export const fbConfig = {
  apiKey: "",
  authDomain: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: "",
  measurementId: ""
};

If I do not pass anithing to the reduxFirestore I get the error TypeError: firestore.collection is not a function, guess because its not initialized properly.

How is the firebase config supossed to be passed to the reduxFirestore?

question from:https://stackoverflow.com/questions/65870523/pass-in-firebase-config-to-reduxfirestore-typescript-typeerror-firestore-colle

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...