-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue with use
, string value works but object value fails to compile
#65272
Comments
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 |
Thanks. Yeah, this has been the case for a long time. If I remember correctly, I discovered that I'm wondering if I'm correct and what's the proper way to use |
@ElectricCodeGuy it's recommended to use async/await for data fetching?
https://react.dev/reference/react/use#caveats However, this is not answering the issue I am facing. |
@eps1lon @delbaoliveira created the issue here from X https://x.com/sebsilbermann/status/1785979252686385321 |
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? |
It should fail compilation since 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" |
|
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/use-use-x3pns4
To Reproduce
pnpm run dev
app/components/button.tsx
Current vs. Expected behavior
while using
use
, context value as a string works fine but context value as an object is not working.String value working fine:
components/theme-provider.tsx
Here theme value is either dark or light, which is a string.
Object value is not working:
components/user-provider.tsx
AND reading value using
use
from context returns empty objectoutputs
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Available memory (MB): 4102 Available CPU cores: 2 Binaries: Node: 20.11.1 npm: 10.2.4 Yarn: 1.22.19 pnpm: 8.15.4 Relevant Packages: next: 14.3.0-canary.36 // Latest available version is detected (14.3.0-canary.36). eslint-config-next: 14.2.1 react: 18.2.0 react-dom: 18.2.0 typescript: 5.4.5 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Not sure, Runtime, Upstream
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local)
Additional context
none of the versions are working including canary. Not sure whether this one is a React issue or Next!!!
The text was updated successfully, but these errors were encountered: