Comments (6)
Thanks. Yeah, this has been the case for a long time. If I remember correctly, I discovered that use
can be utilized on both server and client components. Additionally, on react.dev, it's documented as an API instead of hooks. https://react.dev/reference/react/use
I'm wondering if I'm correct and what's the proper way to use use
!!
from next.js.
@ElectricCodeGuy it's recommended to use async/await for data fetching?
When fetching data in a Server Component, prefer async and await over use. async and await pick up rendering from the point where await was invoked, whereas use re-renders the component after the data is resolved.
https://react.dev/reference/react/use#caveats
However, this is not answering the issue I am facing.
from next.js.
This is because you are trying to use React client hook in a server component. Did you read this? - https://nextjs.org/docs/messages/react-client-hook-in-server-component
from next.js.
@eps1lon @delbaoliveira created the issue here from X https://x.com/sebsilbermann/status/1785979252686385321
from next.js.
Does it not compile or does it just silently return the wrong context value? Is it the default that it returns or always an empty object?
from next.js.
It should fail compilation since use(SomeContex)
implies you import a file using createContext
in a server component. This is not supported since React Context is a client-only feature.
You should see an error similar to "createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component"
from next.js.
Related Issues (20)
- Next 14 is not working properly in docker on windows with bun, but normal at local terminal HOT 4
- Sourcemaps are not loaded in index pages with a dynamic route level deeper than one
- SVG with icons not updating after change HOT 6
- [backport request] Backport fix of an already-fixed bug of next-swc HOT 5
- FileList is not defined on client component HOT 2
- Memory Leak with Image Optimization in Next.js Docker Environment
- When tried to deploy latest canary to vercel -- Error: Invariant: prefetchDataRoute can't be set without PPR HOT 3
- Revalidate does not work on Vercel Deployment only HOT 1
- Buffer polyfill not work on ios lower then 14 HOT 1
- Buffer polyfill not work on ios lower then 14 HOT 5
- Custom page extension + own sitemap/robots route bug - route source code returned instead of Response HOT 2
- Router cache does not revalidate HOT 3
- Importing svg's using svgr/webpack no longer works in the latest canary release when using ppr (error: Cannot read properties of undefined (reading 'stack'))
- Unexpected token Ident("tr") HOT 1
- outputFileTracing increases export build time by 1.5-2x HOT 1
- In iPhone Safari browser, quickly clicking the refresh button will cause the page to always display the content from loading.tsx
- Turbopack error on edge runtime(middleware): `Error [TypeError]: _react.default.createContext is not a function` HOT 2
- Invalid hook call error
- Double RSC fetch after server action redirect HOT 1
- Double RSC fetch after server action redirect HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.