Next.js: Hooks don't work with React 16.8

Created on 6 Feb 2019  路  2Comments  路  Source: vercel/next.js

Hello there, I upgraded React and React-DOM to version 16.8.0 to use hooks. I was not using the alpha before.

Whenever I try to use a hook, I get the error Object(...) is not a function.

Here's an example that causes the bug:

import React, { useState } from 'react'

const Component = () => {
  const [count, setCount] = useState(0)
  return <h1>{count}</h1>
}

I looks similar to the issue #5991.

Most helpful comment

Thanks for the quick response.

Turns out I had to restart the Next server to make it work after updating react. I should have investigated more on my own before posting this issue, but hopefully this can help someone.

All 2 comments

Please follow the issue template when creating issues. I can't reproduce the issue you're describing based on the provided steps. The provided code runs completely fine for me when I create a new directory, add next react react-dom and then create pages/index.js with your code (and additional export default Component.

Thanks for the quick response.

Turns out I had to restart the Next server to make it work after updating react. I should have investigated more on my own before posting this issue, but hopefully this can help someone.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

havefive picture havefive  路  3Comments

DvirSh picture DvirSh  路  3Comments

irrigator picture irrigator  路  3Comments

rauchg picture rauchg  路  3Comments

jesselee34 picture jesselee34  路  3Comments