-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Fetch from Cloud Firestore #37
Comments
Your integration with firebase isn't really correct, the forEach method that you area calling doesn't return to the "then" method, you have to set an accumulator and then pass it to the dispatcher. Also, you're probably dispatching before the articles are fetched. |
You could try something like this: fetch: effect(async (dispatch, payload, getState) => {
}) |
Thanks, that was smart! I tried that, but I still get an endless loop and no data shown when trying to render. Also tried to console.log the state... endless loop here too.
|
Where are you calling the "initialise" method? |
In the parent component of the Article component.
|
That's it, you shoudn't call the initialise method inside the useEffect hook |
The Easy-Peasy example did that. Where should it be called then? Where ever I call it it goes to infinite loop.. |
The useEffect triggers whenever your app mount, and when your state update, so when the articles are fetched, it will call the useEffect again... You can call the initialise method outside the useEffect, or simple add the second argument [] to useEffect, so it will run only on the initial mount. Edit: Dont't call the method outside the useEffect, follow the example of my next comment. |
It is more advised to just use the [] argument option, like:
|
Ahhhh!!! Solved it. Where can I find info about second argument []? Nothing in the React docs. Also had to change the fetched action to this:
|
You can find more about the [] argument in the docs, look for the footer note: |
I am trying to fetch data from my Cloud Firebase, but I can't figure out how to do it. I tried following the guide, but nothing works. I am only getting in an endless loop. What am I doing wrong?
My store
My simple article component:
The text was updated successfully, but these errors were encountered: