Coder Social home page Coder Social logo

Comments (6)

rashidul0405 avatar rashidul0405 commented on May 26, 2024 1

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.

rashidul0405 avatar rashidul0405 commented on May 26, 2024 1

@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.

poorvasingh04 avatar poorvasingh04 commented on May 26, 2024

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.

rashidul0405 avatar rashidul0405 commented on May 26, 2024

@eps1lon @delbaoliveira created the issue here from X https://x.com/sebsilbermann/status/1785979252686385321

from next.js.

eps1lon avatar eps1lon commented on May 26, 2024

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.

eps1lon avatar eps1lon commented on May 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.