Git Product home page Git Product logo

Comments (6)

adrai avatar adrai commented on June 7, 2024

You need to create something similar to this Footer component: https://github.com/i18next/next-app-dir-i18next-example/tree/main/app/%5Blng%5D/components/Footer

from react-i18next.

adrai avatar adrai commented on June 7, 2024

basically, pass the t function down to the Server and or the Client component so you don't need to call useTranslation in those components

from react-i18next.

tomgwasira avatar tomgwasira commented on June 7, 2024

Awesome. Thanks Adriano. So, just to clarify, it doesn't matter that I'm passing t created from a client component into a server component and vice versa? It seems to work alright.

And also, when do we use useTranslation in a child component and when do we pass t to the child as a prop. In the Footer example, app/[lng]/client-page/page.js does not pass t to the child component Footer; instead, Footer calls useTranslation.

Thanks again.

from react-i18next.

adrai avatar adrai commented on June 7, 2024

the t function can be passed to any component... that should never be a problem...
The Footer example is a little bit different than your example... it has a FooterBase component (receiving the t function via prop), used by the Footer component of the client or used by the Footer component of the server. => so the useTranslation call is always specific to the environment (client or server), and the t function can be passed to whatever component you like

from react-i18next.

tomgwasira avatar tomgwasira commented on June 7, 2024

I see. Thanks so much for the help!

from react-i18next.

tomgwasira avatar tomgwasira commented on June 7, 2024

Currently passing lng and calling useTranslation in the child when the parent is a server component and the child is a client component because of error: 'Functions cannot be passed to Client components'. For everything else, I pass the t function down. I would like to believe React will work on making this possible in the future.

from react-i18next.

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.