-
Notifications
You must be signed in to change notification settings - Fork 65
Alternative external component representation #139
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
Comments
This is fundamentally unsafe, so I'm not sure that a module Foo (foo) where
import React (ReactClass, ReactElement, unsafeCreateElement)
import React.DOM.Props (Props, unsafePropsFromArray)
foreign import fooClass :: forall r. ReactClass { | r }
foo :: Props -> Array ReactElement -> ReactElement
foo = unsafeCreateElement fooClass <<< unsafePropsFromArray You don't have the issue with |
Actually, you probably don't even need that. Since |
Yes. You're right. Good call on the annotation. Thanks! Full example: module Bar (bar) where
bar :: Array Props.Props -> Array React.ReactElement -> React.ReactElement
bar props children = React.createElement barComponent (Props.unsafeFromPropsArray props :: Record ()) children
someBarProp :: String -> Props.Props
someBarProp = Props.unsafeMkProps "someBarProp"
foreign import barComponent:: React.ReactClass (Record (children :: React.Children)) |
In addition to the representation described in #96 for foreign components, sometimes it is handy to represent an externally defined component as follows:
In this representation one is able to pass any of the props defined in
React.DOM.Props
. This can be useful if the external component forwards props to an underlying DOM element, for example.However, this representation fails to compile with:
I am wondering if there is a way to implement this kind of representation or something similar.
//cc @natefaubion
The text was updated successfully, but these errors were encountered: