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

Feature: Allow an initial value to be returned by the hooks #190

Closed
dylanwatsonsoftware opened this issue Dec 18, 2021 · 5 comments
Closed

Comments

@dylanwatsonsoftware
Copy link
Contributor

dylanwatsonsoftware commented Dec 18, 2021

In NextJS the idea is that you preload the data at build time. This then gets passed to your component via props.

If I have a component that uses say useCollectionData, it would be useful to specify an initial value that the hook should return whilst the data is loading. As soon as the firebase query has loaded, this value would be ignored and replaced with the value from the firebase query.

It is currently possible to do this outside of the firebase hook but it's a little awkward and this would really simplify the code for this usecase (i.e any nextjs project)

I think it'd be a pretty simple change so happy to put up a PR if you'd be interested in accepting a feature like this.

Thanks,
Dylan.

@chrisbianca
Copy link
Contributor

Hi Dylan, this sounds like it would be a very useful feature so am more than happy to review a PR for it. As you say it should be a relatively simple change, but shout if you have any issues and I am happy to take a look myself.

@dylanwatsonsoftware
Copy link
Contributor Author

Ok awesome. will try to find time this week to take a look and see how far I get!

@dylanwatsonsoftware
Copy link
Contributor Author

So, I finally got a local copy of react-firebase-hooks hooked up to my local project.
For those giving it a go, the main issue was that I need to:

  1. Run npm link in the root of the library directory
  2. Run npm link react-firebase-hooks in the root of my projects directory
  3. The step missing from most documentation was that I then needed to run npm link in the react-firebase-hooks/node_mopdules/react directory to ensure that both projects used the same version of react
  4. Then run npm link react in the root of the project directory

@dylanwatsonsoftware
Copy link
Contributor Author

dylanwatsonsoftware commented Dec 20, 2021

NextJS seems to have some issues with Firebase v9 so my plan is to raise the PR against the v3 branch and let you pull it into master later.

@chrisbianca
Copy link
Contributor

Now part of: https://github.com/CSFrequency/react-firebase-hooks/releases/tag/v3.0.5

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

2 participants