Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs]: Suggested solution for reusing tags in t.rich elements is unnecessarily complex #1465

Closed
JosipPardon opened this issue Oct 24, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation Stale unconfirmed Needs triage.

Comments

@JosipPardon
Copy link

JosipPardon commented Oct 24, 2024

Link to page

https://next-intl-docs.vercel.app/docs/usage/messages#rich-text-reuse-tags

Describe the problem

Solution described in https://next-intl-docs.vercel.app/docs/usage/messages#rich-text-reuse-tags is very complex. Much simpler and better solution is this:

export const defaultTags: Record<string, (chunks: ReactNode) => ReactNode> = {
  i: (chunks) => <i>{chunks}</i>,
  /*more tags*/
};

and then:

t.rich("richTextTest", defaultTags)

Also, docs don't describe how to combine default tags with specific ones. Solution is this:

t.rich("richTextTest", {
  ...defaultTags,
  specific: (chunks) => (
    <span style={{ color: "orange" }}>{chunks}</span>
  ),
})
@JosipPardon JosipPardon added documentation Improvements or additions to documentation unconfirmed Needs triage. labels Oct 24, 2024
@amannn
Copy link
Owner

amannn commented Oct 25, 2024

Thanks for the feedback!

Your solution was in fact considered in #611 and is absolutely fine.

However, I went for the render prop way in the docs since it's slightly more flexible IMO:

  1. Elements are created in render, giving you the full power of React to construct them (e.g. call hooks beforehand)
  2. Can provide an overall layout (e.g. spacing between <p>)

So yes, it's a bit more code up front, but I believe it provides more flexibility without having to think much about it.

I'll leave this open for a bit to see if more users feel this way, would be curious about more opinions!

Copy link

This issue has been automatically closed because there was no recent activity and it was marked as unconfirmed. Note that issues are regularly checked and if they remain in unconfirmed state, they might miss information required to be actionable or are potentially out-of-scope. If you'd like to discuss this topic further, feel free to open a discussion instead.

@github-actions github-actions bot added the Stale label Nov 25, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation Stale unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants