title: NextJS - Invalid hook call. Hooks can only be called inside of the body of a function component
body: <p>I'm getting this error when trying to build with NextJS. I don't use styled-components. I tried deleting node_modules etc. without luck. I tried adding aliases and resolves for <code>react</code> in my next.config.js file and package.json without luck. I'm using react 16.8.6, react-dom 16.8.6, and next 9.0.4. <code>npm ls</code> says there's only one of each. The app uses material-ui. I am not using any npm links. I got the error in a <a href="https://github.com/dancancro/questions/tree/invalid-hook-call" rel="nofollow noreferrer">version</a> without any hooks and in a <a href="https://github.com/dancancro/questions/tree/convert-to-function-component" rel="nofollow noreferrer">version</a> with only functional components and hooks.</p>
  
  <p>The repo is here: <a href="https://github.com/dancancro/questions/tree/convert-to-function-component" rel="nofollow noreferrer">https://github.com/dancancro/questions/tree/convert-to-function-component</a></p>
  
  <p>Codesandbox is here: <a href="https://codesandbox.io/s/stop-indoctrination-5xfpi" rel="nofollow noreferrer">https://codesandbox.io/s/stop-indoctrination-5xfpi</a></p>
  
  <p>The error is here: <a href="https://gist.github.com/dancancro/2dfafb053aaaedfade406fd4f67eb68a" rel="nofollow noreferrer">https://gist.github.com/dancancro/2dfafb053aaaedfade406fd4f67eb68a</a>
  render -> renderToString -> ReactDOMServerRenderer.read -> ReactDOMServerRenderer.render -> Object.WithStyles [as render] ...</p>
  
  <p>The offending hook is a <code>useStyles()</code> call on line 17428 of this file in a <code>withStyles</code> function. Search for "var classes = useStyles(props)". The problem is with nextjs-generated code. The code I wrote doesn't use <code>withStyles</code> or any hooks or any functions that start with "use*"</p>
  
  <p><a href="https://raw.githubusercontent.com/dancancro/questions/invalid-hook-call/.next/static/development/pages/index.js" rel="nofollow noreferrer">https://raw.githubusercontent.com/dancancro/questions/invalid-hook-call/.next/static/development/pages/index.js</a></p>