Skip to content

Best way to create utility functions for use in async and sync components. #1357

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

You must be logged in to vote

Yep, that's true. The t function needs to be unscoped in this case though, containing all possible translations. That in turn could make the usage of t harder in the calling component, if it also has to render translations. This sounds like an indicator to me that t should really be retrieved as part of your format distance utility (whether it's an async function, hook or component).

Personally, I like to use async components rather sparingly for data fetching and typically leave all rendering behavior to non-async components. This has the nice side effect that aspects like testing, isolated rendering in Storybook etc., work without tradeoffs. In this case it'd also help to offer a single u…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@jamiematthews21
Comment options

@amannn
Comment options

Answer selected by jamiematthews21
@jamiematthews21
Comment options

@amannn
Comment options

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