FormidableLabs/react-ssr-prepass

Throwing error: Hooks can only be called inside the body of a function component.

ashbuilds opened this issue · 3 comments

Hi, I'm trying to implement this in nextJs app. I'm currently calling it inside a component's static async getInitialProps(ctx) { but it is throwing error as i mentioned in title.

But after I commented out in this package file: src/internals/dispatcher.js

//  if (currentIdentity === null) {
//    throw new Error(
//      '[react-ssr-prepass] Hooks can only be called inside the body of a function component. ' +
//        '(https://fb.me/react-invalid-hook-call)'
//    )
//  }
 

Just to see if it will work or not, surprisingly it works great after.

May i know why we throw this error? Is there any side-effects commenting this?

Sorry for the late reply!

This can happen if you have multiple versions of react installed, so it's not related to react-ssr-prepass.

I'm getting this error also, and I only have one version of react installed, according to my yarn.lock file.

My App component doesn't make invalid hook calls, and can render (renderToString or render in dom) without any errors like this.

@kitten The error is being thrown from this library (not react) so is there any possible explanation for this? I may need to look into this myself and see if I can find the appropriate fix. (please reopen issue)

Closed still since @zenflow seems to have found the culprit