Skip to content

createPortal #21

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

Open
andys8 opened this issue Jan 18, 2021 · 1 comment
Open

createPortal #21

andys8 opened this issue Jan 18, 2021 · 1 comment
Labels
good first issue First-time contributors who are looking to help should work on these issues. type: enhancement A new feature or addition.

Comments

@andys8
Copy link

andys8 commented Jan 18, 2021

I noticed react-dom has a portal feature but createPortal is missing here. If there Is no reason against it, I would suggest adding the functionality.

ReactDOM.createPortal(child, container)

https://reactjs.org/docs/react-dom.html#createportal
https://reactjs.org/docs/portals.html

@thomashoneyman thomashoneyman added type: enhancement A new feature or addition. good first issue First-time contributors who are looking to help should work on these issues. help wanted labels Jan 18, 2021
@thomashoneyman
Copy link
Contributor

thomashoneyman commented Jan 18, 2021

@andys8 I'm surprised it's not already here. From a quick look at the implementation, we can provide an FFI definition along these lines:

                               -- container   -- child        -- optional key  -- resulting portal
foreign import createPortal :: HTMLElement -> ReactElement -> Maybe String -> ReactElement

I would need to spend a little more time to verify these types. For example, it's not clear:

  1. Whether HTMLElement is the most appropriate type for the container (it's usually a sensible default, but it may be too general or too restrictive for portals)
  2. Whether ReactElement is the most appropriate type for the child (technically, React accepts any 'react node', which includes fragments, strings, and numbers, but to be usable it seems sensible to me to use ReactElement)

Ideally portals would be usable like any other ReactElement, which is why I didn't suggest introducing a new ReactPortal type as React does in their TypeScript definitions. So the above type is my best estimate of what type we might introduce for this feature, though other maintainers may have their own ideas.

We could support both keyed and non-keyed variants instead of including the optional argument:

-- no key
createPortal' :: HTMLElement -> ReactElement -> ReactElement

-- with key
createPortal :: HTMLElement -> ReactElement -> String -> ReactElement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue First-time contributors who are looking to help should work on these issues. type: enhancement A new feature or addition.
Development

No branches or pull requests

3 participants