Swr: How to yarn link swr? `Error: Invalid hook call`

Created on 22 Dec 2019  路  1Comment  路  Source: vercel/swr

Hey,

Sorry for the noob question, how do I yarn link swr?

I'm getting the following?

Error: 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.

I'm using next js and have tried setting an alias as suggested here: https://github.com/facebook/react/issues/14257 but no luck.

const path = require('path')

module.exports = {
  webpack(config, options) {
    config.resolve.alias['react'] = path.join(__dirname, 'node_modules/react')
    return config
  },
}
help wanted

Most helpful comment

I was able to get things working by yarn linking react and react-dom from my app into swr.

eg:
my-app/node_modules/react> yarn link
my-app/node_modules/react-dom> yarn link
swr> yarn link react
swr> yarn link react-dom

A little bit fiddly so I'd be curious if someone has a better solution.

>All comments

I was able to get things working by yarn linking react and react-dom from my app into swr.

eg:
my-app/node_modules/react> yarn link
my-app/node_modules/react-dom> yarn link
swr> yarn link react
swr> yarn link react-dom

A little bit fiddly so I'd be curious if someone has a better solution.

Was this page helpful?
0 / 5 - 0 ratings