-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add an example which includes an external component #2
Comments
Would this include to/from functions for |
Specifically, I was thinking about stealing reason-react's "reducer" component (very similar to elm/pux/redux, but using component state). Examples: |
I was thinking more about components from NPM. I haven't really thought too much about adapters, but I think I would prefer for them to be in a separate library. I considered going via This library is pretty much tailor-fit for our use cases right now, but if the need for lifecycle methods comes up, we'll have to find a way to include them, hopefully without complicating the API. Yes, I expect a Redux/ElmArch layer on top of this would be quite useful. |
Hello, were these examples ever added? I'd be interested in wrapping external components 🌯 |
Not yet, although they basically amount to using the FFI to pull in the component class as a value and then using it as normal. |
Example for (simplified) React Router Route component: type RouteProps =
{ path :: String
, exact :: Boolean
, render :: MatchedRouteProps -> JSX
}
foreign import route :: ReactComponent RouteProps |
But what would the |
Something like this: "use strict";
var RR = require("react-router");
exports.route = RR.Route; |
Thank you very much, for my example (a material UI button) it was this: foreign import button ::
ReactComponent { onClick :: EventHandler, children :: Array JSX, color :: String, variant :: String } 'use strict'
exports.button = require("@material-ui/core/Button").default; I'm also curious how I could make all the fields of the |
You can use the same This only works for FFI -- the type it creates can't really be implemented using PureScript. You can make some fields required by putting them in the Record type instead of the Union: a
:: forall attrs attrs_
. Union attrs attrs_ Props_a
=> { someRequiredField :: Asdf | attrs }
-> JSX |
Can this be reopened with the outcome of having an example? Or even multiple examples? There appears to be no information yet on how to deal with external components. Or perhaps as it appears there is no one true way, what I'm looking for is an overview of the options people have thought of. I'll share mine. The following is all in the context of larger external components as often found in frameworks or libraries.
type ButtonProps = { onClick :: Effect Unit, disabled :: Boolean }
foreign import button ::
forall props props_. Union props props_ ButtonProps =>
ReactComponent (Record props) It appears easy to break. I broke it, by moving the union outside the foreign import. Spent time understanding FFI more deeply, fixing it. Similarly, this method appears to break down when some props are sets of props themselves.
|
I need to clean up my lib -- https://github.com/jvliwanag/purescript-oneof . But adding it as an option as well. It allows for simple record declarations: type Props =
{ name :: UndefinedOr String
, foo :: UndefinedOr (String |+| Number |+| Boolean)
}
foreign import _myButton :: ReactComponent Props
myButton :: forall r. Coercible r Props => r -> JSX
myButton = element _myButton <<< coerce
sample = myButton { foo: "bar" } -- can omit name |
I wouldn't mind having an FFI example. You're correct that it's more because there's no one way to do it, and it's not really different from any other PureScript FFI.
|
Lots of good options, some new to me. Thanks! |
It would be good to demonstrate that we can use other components easily.
The text was updated successfully, but these errors were encountered: