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

Example with nextjs doesn't work with React hooks #601

Open
Siegrift opened this issue Aug 11, 2019 · 6 comments
Open

Example with nextjs doesn't work with React hooks #601

Siegrift opened this issue Aug 11, 2019 · 6 comments

Comments

@Siegrift
Copy link

How to reproduce these conditions

I have set up an example repo where you can check the bug.

Steps to set up and reproduce

  1. git clone https://github.com/Siegrift/nextjs-firebase-example
  2. cd src/app
  3. yarn && yarn dev
  4. navigate to http://localhost:3000/about
    You will get:
    Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
    See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.

Expected behavior

I don't think that this example is valid anymore. I was trying to figure out how to make nextjs work with firebase, but I couldn't figure it out.... Anyway, the expected behaviour is to make it work with nextjs and newest React (e.g. react hooks).

Actual behavior

Error in application and I am unable to configure nextjs with firebase.

@maotora
Copy link

maotora commented Oct 19, 2019

Did you solve this?
I'm experiencing the same issue.

@Siegrift
Copy link
Author

Unfortunately no, but I didn't needed that much. I use firebase and firestore and I've set it up manually inside the project (https://firebase.google.com/docs/web/setup)

@maotora
Copy link

maotora commented Oct 19, 2019

So you are hosting your web app on static hosting?
My Nextjs + Antd app got really slow as the size grew bigger so I thought only SSR would lift some rendering load.

I just posted a question on stackoverflow referencing this issue and a fork of your reproducible bug repo.

@Siegrift
Copy link
Author

Siegrift commented Oct 19, 2019 via email

@RahmanQureshi
Copy link

RahmanQureshi commented May 18, 2020

The problem superficially stems from two copies of the react source code. I'm not 100% sure how it works so I won't even try to explain the root cause of the problem.

To fix the problem, please place the app inside the functions folder and remove package.json. Unfortunately, all the dependencies of app must necessarily be dependencies of functions. Then, change next.config.js to this:

'use strict';

module.exports = {
distDir: './next'
};

and index.js to this:

const dir = __dirname + "/app"
const app = next({ dev, dir, conf: {distDir: 'next'} })

@jthegedus
Copy link

Hi, I wrote the initial example. This example hasn't been kept up to date as I was maintaining my own example and the example in the nextjs repo. My most up to date example does function with React hooks if you would like to check that out https://github.com/jthegedus/firebase-gcp-examples/tree/master/functions-nextjs

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

4 participants