-
Notifications
You must be signed in to change notification settings - Fork 66
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
Document creation of stateful react components #87
Comments
...I also had to let inline myComponent model = ofType<MyComponent, MyProps, MyState> { model = model } [] ...to make it usable (I found that pattern in https://blog.vbfox.net/2018/02/06/fable-react-1-react-in-fable-land.html and it works), although I'm not sure what it does and why this is necessary. Please understand... this is not a rant... I just listed a couple of things that I'm struggling with. Although I'm experienced with React , I got a bit overwhelmed with the F#-type details when trying to use React with Fable. I'm not sure how to overcome this knowledge gap. Thanks. |
Hi @pkese! Thanks a lot for your comments. No worries, you're totally right, we're focusing on Elmish apps and still miss documentation about how to write React components directly. This document about how to use 3rd-party React components was recently added and covers some parts, like using the For the rest and for now, you can check the react-todomvc sample that implements React components directly without using any framework. It's a bit old but the only thing that has changed is the need to use It's necessary to use
|
Just thought I'd drop these here, which helped me get started creating stateful React components in Fable: They even go over some of the important optimizations related to lambdas and lists/keys. |
Another thing to watch out for is that the Props type must be an object (e.g. an F# record) if you use a |
Fable can't do that you no because it doesn't know about React. However, it's possible to create an Fsharp Analyzer which can analyze the code for you and generate warning/errors. It's can be integrated in Ionide or invoked by CLI |
I'm not familiar with the Fable internals, but could the Fable.React bindings be annotated with something that tells the Fable compiler to throw an error? |
I've spent some effort on creating a custom react component using
props
andstate
(includingcomponentDidMount
,componentWillReceiveProps
,setState
and such).There's a few lines in source code suggesting to do something like:
... that I tried to follow, but then I got issues with React reporting errors about component's Children being an object rather than react component and such.
I did fiddle something creating some Pojo objects for
MyState
andMyProps
types, but I'm not really sure what I did and if I did it correctly (I was more like a monkey that somehow managed to write a Shakespeare novel).It would be really nice to have the concept of strongly typed
state
andprops
described somewhere in the documentation.The text was updated successfully, but these errors were encountered: