Replies: 9 comments 20 replies
-
The error message suggests two alternatives, have you tried them? I'll convert this to a discussion since this is a usage question. The current architectural direction is explained in more detail here: #406 (comment) |
Beta Was this translation helpful? Give feedback.
-
Thanks for quick reply @amannn. Sorry for posting this without reading the message properly first. Apparently awaitable By the way App folder has become stable since next 13.4 released yesterday. Are you planning to provide a larger example that would provide a more practical way for different use cases? Such as client components, server components (both sync and async) altogether would be really helpful. Because using a provider for client-side is also being suggested in the documentation however also mentioned that it is not ideal in terms of performance. |
Beta Was this translation helpful? Give feedback.
-
Hi! I assume not being able to use I was trying to create a page that receives search params, fetches data according to them and renders a UI that needs to be translated. I started by doing this: // page.tsx
const Page = async ({ searchParams }) => {
const data = await getData(searchParams);
const t = useTranslations();
return (
<div>
{/* render UI with the dynamic data */}
<Link href={{ pathname: "/some-route", query: searchParams }}>{t("someRoute")}</Link>
</div>
);
}; then I get an error telling me I can't use // page.tsx
const Page = async ({ searchParams }) => {
const data = await getData(searchParams);
return (
<div>
{/* render UI with the dynamic data */}
<SomeRouteLink />
</div>
);
};
// SomeRouteLink.tsx
const SomeRouteLink = () => {
const t = useTranslations();
const searchParams = useSearchParams();
return <Link href={`/some-route?${searchParams.toString()}`}>{t("someRoute")}</Link>
}; Now I get an error telling me I can only use // page.tsx
const Page = async ({ searchParams }) => {
const data = await getData(searchParams);
const t = useTranslations();
return (
<div>
{/* render UI with the dynamic data */}
<SomeRouteLink searchParams={searchParams} />
</div>
);
};
// SomeRouteLink.tsx
const SomeRouteLink = ({ searchParams }) => {
const t = useTranslations();
return <Link href={{ pathname: "/some-route", query: searchParams }}>{t("someRoute")}</Link>
}; In my experience, this limitation adds unnecessary layers of complexity that could be avoided if I could just use I'm sure this limitation has its reasons but I hope you consider removing it in the future. |
Beta Was this translation helpful? Give feedback.
-
But does Many of our Server Components are async, because of the recommended granular data fetching and they all need access to the messages. |
Beta Was this translation helpful? Give feedback.
-
Where can I find an extended explanation for this? In particular for TS? One of the issues I encountered is when I split in two - i need to define/import a type of the useTranslations function. Is there a type for this or do I have to define it myself? I am using version 3 beta My example code:
|
Beta Was this translation helpful? Give feedback.
-
Any clean outcome of this discussion? :) The two solutions proposed by default in the error message are quite inconenient to me |
Beta Was this translation helpful? Give feedback.
-
I think it's about the fact that the
|
Beta Was this translation helpful? Give feedback.
-
Sure, there are workarounds. I hope this becomes a priority in the future as we delve deeper into this new paradigm. |
Beta Was this translation helpful? Give feedback.
-
For those following this issue, I've added a comment in #406 to explain the current architectural direction in more detail, hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Description
I'm trying server components example. Everything works fine but I need to turn my pages async since react query hydrate function requires it. Of course there might be other libraries require to use server-side promises. I couldn't find a way to work with server components without turning page into synchronous component. There is no explanation in documentation (or maybe I missed) and I couldn't find an async page example in server components example repo.
However useTranslation function throws an error if page is async :
Mandatory reproduction URL (CodeSandbox or GitHub repository)
Reproduction description
Here is an example page.tsx (it works if I remove 'async' and promises) :
Expected behaviour
Server components might be async functions depending on the requirements. There must be a way to use useTranslations method in async pages as well.
Beta Was this translation helpful? Give feedback.
All reactions