Skip to content

Key is missing when using tailwind #1111

@njbmartin

Description

@njbmartin

Describe the Bug

Due to the way the tailwind component works, it renders an array of children, which requires a key.

So the key needs to be appended to the element like so (note the key would be the index of the map:

export function appendKeyToValidElement(element: ReactNode, key: number): ReactNode {
  if (isValidElement(element) && element.key === null) {
    return cloneElement(element, { key });
  }
  return element;
}

Which package is affected (leave empty if unsure)

@react-email/tailwind

Link to the code that reproduces this issue

https://github.com/resend/react-email

To Reproduce

Start the demo and render the tailwind example. You will see the following warning in the console:

image

Expected Behavior

React elements should rendered with a valid key.

What's your node version? (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions