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

Pass index to T.$ function calls #31

Open
mikeselander-1p opened this issue Dec 14, 2022 · 0 comments
Open

Pass index to T.$ function calls #31

mikeselander-1p opened this issue Dec 14, 2022 · 0 comments

Comments

@mikeselander-1p
Copy link

When using T.$() within a React context, each applied replacement requires a React key in the replaced react tag, or a key error will throw. This is easy enough to fix in a a simple string, but if you are replacing multiple spots in the same string with a single replacement, you'll end up with key issues regardless.

Instead of the following:

T.$<ReactNode>(
	"Some text <bold>that should be be bolded</bold> with more text that is also <bold>emphasized</bold>",
	{
		bold: (text) => (
			<strong key="i-will-be-duplicate">{text}</strong>
		),
	},
)

getting something like:

T.$<ReactNode>(
	"Some text <bold>that should be be bolded</bold> with more text that is also <bold>emphasized</bold>",
	{
		bold: (text, index) => (
			<strong key={`no-duplicate-${index}`}>{text}</strong>
		),
	},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant