skip to Main Content

I am trying to try out new features of React 19.

In order to do that, I have created React app with Vite and TypeScript:

npm create vite@latest

Then upgraded to React 19 libraries (accoridngly to this article):

npm install --save-exact react@rc react-dom@rc

After this I can see upgraded React version in package.json:

"dependencies": {
    "react": "19.0.0-rc-d8c90fa4-20241001",
    "react-dom": "19.0.0-rc-d8c90fa4-20241001"
}

Now I want to try out new React 19 features, one of which is new hook use, but when I try:

import { use } from 'react'

I get an error that it’s not exported from react:

Module "react" has no exported member ‘use’

Obviously, I did now complete correctly "migration" to React 19 – what did I miss? How to make it work?

I also have suspicion that this feature might be specific to React Server Components..

3

Answers


  1. Chosen as BEST ANSWER

    As could be read in GitHub issue

    It is only available in canary channel docs

    So, at page of react npm I found latest Canary version: 19.0.0-canary-cb151849e1-20240424 and I have installed it for react and react-dom.

    Now, everything seems to be working with use hook, however the error remains.


  2. you actually can not use the use inside a typescript project, because the react.d.ts do not have the use member.

    Go with a js project and it will work as expected.

    I set up a really quick project to use React 19 if you want to React 19

    Login or Signup to reply.
  3. The @types/react you’re using don’t yet have that name, so TypeScript is confused.

    You could try a local module augmentation file (e.g. src/react-19.d.ts):

    declare module "react" {
      export function use(); // fill in with the correct signature
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search