Skip to content

How to return translations from functions outside of React components #1575

Answered by amannn
kuchejak asked this question in Q&A
Discussion options

You must be logged in to vote

This seems similar to how Zod can be used in Server Actions, while using translations.

What happens is basically:

  1. Zod returns a data structure that describes an error
  2. The calling Server Action retrieves t from await getTranslations and turns the data structure into a human-readable error message (could also be a component in your case)

It's essentially the same pattern that's also described in the blog post:

we can format messages during the rendering phase of React, turning data structures into human readable strings

So I'd try to avoid coupling your checkSomething function to translations, but it could for example return error codes (e.g. code: 'PROBLEMATIC_MEMBER'), potentially wit…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kuchejak
Comment options

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