Next.js 13 use() not working for Client Components
See original GitHub issueVerify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000
Binaries:
Node: 16.15.0
npm: 8.5.5
Yarn: 1.22.19
pnpm: 7.5.2
Relevant packages:
next: 13.0.1-canary.0
eslint-config-next: 13.0.0
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
Chrome 106.0.5249.119 (Official Build) (arm64)
How are you deploying your application? (if relevant)
In development
Describe the Bug
Getting error TypeError: Cannot read properties of null (reading 'use')
when trying to use use()
and fetch
with Client Components.
I’m using the same snippet code example provided in the Docs for Client Component Data Fetching with the use()
hook and fetch()
Expected Behavior
use()
hook function should be defined and imported from react without issues.
Link to reproduction
https://codesandbox.io/p/github/ipenywis/nextjs-client-component-issue
To Reproduce
Navigate to /client-component
route, you will see an “Unhandled Runtime Error” saying TypeError: Cannot read properties of null (reading 'use')
The file is under app/client-component/page.tsx
Issue Analytics
- State:
- Created a year ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Rendering: Server and Client Components - Next.js beta docs
Learn how use Server and Client Components in your Next.js application. ... This allows you to automatically adopt Server Components with no extra...
Read more >Next.js 13 - Server & Client Component Basics - YouTube
In this video, we'll be learning about Next. js 13 server & client component basics. Next. js is a powerful JavaScript library that...
Read more >React Server vs Client components in Next.js 13 - Ankita
What is Serialization? Serialization is an important topic to know if you are going to use Client and Server components. You'll learn why...
Read more >How to handle SEO for client components in Next.js 13?
You can't use hooks on server components. Server components are rendered on the server side, and thus can't hold state like ...
Read more >What's new in Next.js 13, and what do they really do?
Any client-side state is not lost, however. 5. A good rule of thumb. Use Server Components if: You need to fetch data from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Great, will close this issue then. Keep in mind that
use(fetch())
is not supposed to work yet in client components and that it’s recommended to fetch in server components regardless of it not being available yet.https://beta.nextjs.org/docs/app-directory-roadmap → search for
use() and fetch() in Client Components
Based on the messages above it seems this issue can be closed, is that the case?