Skip to content

pass t function as props #1379

Closed Answered by ScreamZ
sahandsn asked this question in Q&A
Sep 28, 2024 · 4 comments · 6 replies
Discussion options

You must be logged in to vote

This is not the « recommended pattern », but in my humble opinion it does exactly what we want and I love using it :

import type { useTranslations } from "next-intl";
import type { getTranslations } from "next-intl/server";

export type TFn =
  | ReturnType<typeof useTranslations<never>>
  | Awaited<ReturnType<typeof getTranslations<never>>>;

const yourCustomCode = (t: TFn) => {
  // Your code
}

Is the simplest way to export it.

Recommended way is here #1134 but I don't like it much

Replies: 4 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@sahandsn
Comment options

@sahandsn
Comment options

@ScreamZ
Comment options

Comment options

You must be logged in to vote
3 replies
@sahandsn
Comment options

@sahandsn
Comment options

@ScreamZ
Comment options

Answer selected by sahandsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants