Comments (6)
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.
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.
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.
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.
I see. Thanks so much for the help!
from react-i18next.
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)
- `Trans` context handled differently from `t` function HOT 10
- `context` values resolved differently (and incorrectly) between `<Trans />` and `t(...)` HOT 5
- `Trans` component should NOT modify the input props value. HOT 1
- Less than sign `<` breaks tag parsing with Trans component HOT 1
- 18n.exists() not working properly? HOT 6
- google play console rejected due to java error HOT 8
- i18n.changeLanguage dont work if we setup our app using SSR razzle example in react-i18next HOT 5
- Client translation in NextJS 14 breaks React hooks rules HOT 3
- Argument of getFixedT is ignored HOT 12
- Generated types not working with unescape "- " syntax HOT 1
- Typescript error: Context is not assignable to type 'string' HOT 5
- Not existing context not detected as type error if covered by string union HOT 2
- TS Context error when using json for storing translations HOT 1
- Trans component modifies passed tOptions and overrides "context" property from the object HOT 1
- Proposal: useLanguage hook HOT 2
- Anchor tag not working on Trans component HOT 3
- [Bug][IOS]: Error - Multiple commands produce React-Core-3e4f9a72-RCTI18nStrings | React-Core.common-RCTI18nStrings HOT 2
- Trans component using context has unexpected type errors HOT 2
- No React update when updating resource bundle in i18next HOT 1
- Text content did not match & Error while hydrating HOT 3
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 react-i18next.