Skip to content

Add key to createPortal reference doc #5927

@mattrunyon

Description

@mattrunyon

The createPortal reference page does not mention that you can pass key as the 3rd param to createPortal. This is in both the typescript definitions and here is the implementation

Reconciliation appears to be different if you pass the key to createPortal and not the element passed to createPortal. React dev tools does not seem to show the portal element, so it's not clear in dev tools if you have many sibling portals w/ the key set on the element and not the portal.

My use case where I ran into this was using a layout manager that is not React first, so the React support is kind of an afterthought. I made a change from calling render to createPortal so I could get an array of portals and render them inside my app's React tree and use contexts (render just creates a bunch of sibling root trees).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions