Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getFirestore in redux-thunk #785

Closed
petermarks12 opened this issue Oct 24, 2019 · 6 comments
Closed

getFirestore in redux-thunk #785

petermarks12 opened this issue Oct 24, 2019 · 6 comments

Comments

@petermarks12
Copy link

How to access firestore to read and write data in redux thunk. Only getFirebase is available, not getFirestore in the latest release v3.

@prescottprue
Copy link
Owner

You should be able to do getFirebase().firestore() to access it for now, but I will look into why getFirestore isn't exported

@prescottprue
Copy link
Owner

Just remember that getFirestore is actually exported from redux-firestore, so if you want to add it to your thunk integration you would grab it from there. Thanks for reaching out

@petermarks12
Copy link
Author

I request you to please update docs because I can only see getfirebase, not getfirestore, even after doing search in docs. It will be helpful for those who just started using this library for the very first time. I started using it around 1 month back so I thought you have removed it in v3 since it was not working for me at that moment. Also, thanks for solution, now it works.

@FiskaniC
Copy link

FiskaniC commented Nov 18, 2019

@prescottprue I can confirm that getFirebase().firestore() works when using redux thunk

@petermarks12 you can replease getFirestore with the above for now

@henrymingwu
Copy link

I'm working through a similar issue right now (while migrating from v2 to v3 of react-redux-firebase), but seeing (I think) that the instance of firestore exposed through getFirebase().firestore() (in v3) doesn't have access to the same statics as the one that getFirestore() exposed (in v2).

Specifically, statics like firestore.Timestamp and firestore.FieldValue don't seem to be available on the firestore instance exposed through getFirebase().firestore().

In V2, this was working:

export const someAction = (someDate) => {
  return (dispatch, getState, { getFirebase, getFirestore }) => {
    const firestore = getFirestore();
    const convertedDate = firestore.Timestamp.fromDate(someDate);
    // ...
  };
};

In V3:
Does not work, with error Uncaught TypeError: Cannot read property 'fromDate' of undefined

export const someAction = (someDate) => {
  return (dispatch, getState, { getFirebase }) => {
    const firestore = getFirebase().firestore();
    const convertedDate = firestore.Timestamp.fromDate(someDate);
    // ...
  };
};

Workaround that does work:

export const someAction = (someDate) => {
  return (dispatch, getState, { getFirebase }) => {
    const convertedDate = getFirebase().firestore.Timestamp.fromDate(someDate); // Access the service namespace directly instead of from the instance
    // ...
  };
};

Is this expected @prescottprue ? Thanks!

@capi1O
Copy link

capi1O commented Apr 26, 2020

I confirm that getFirebase().firestore() is a different instance than the one exposed via useFirestore for example.

For example firestore().add('/some-collection', document) does not work (must use firstore().collection('some-collection').add(document).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants