Giter Site home page Giter Site logo

Comments (6)

SirUppyPancakes avatar SirUppyPancakes commented on August 19, 2024 5

Just thought I'd drop these here, which helped me get started creating stateful React components in Fable:
https://blog.vbfox.net/2018/02/06/fable-react-1-react-in-fable-land.html
https://blog.vbfox.net/2018/02/08/fable-react-2-optimizing-react.html

They even go over some of the important optimizations related to lambdas and lists/keys.

from fable-react.

pkese avatar pkese commented on August 19, 2024 1

...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.

from fable-react.

alfonsogarciacaro avatar alfonsogarciacaro commented on August 19, 2024

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 Pojo attribute to compile a record as a plain object instead of a class so Rresteact doesn't complain (we want to remove the need of the attribute in Fable 2).

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 override when implementing methods from the React.Component parent (like render, shouldComponentUpdate, etc).

It's necessary to use ofType because React doesn't instantiate directly component classes (this is transparent to JS devs because of the JSX syntax). You can find other helpers to render React components/elements here (most of them compile to React.createElement).

BTW, you can use the reactiveCom helper to quickly write an Elmish-like stateful React component just by passing functions and without implementing the class yourself.

from fable-react.

njlr avatar njlr commented on August 19, 2024

Another thing to watch out for is that the Props type must be an object (e.g. an F# record) if you use a string or similar it will fail at run-time. Perhaps Fable could generate a compiler error here?

from fable-react.

MangelMaxime avatar MangelMaxime commented on August 19, 2024

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

from fable-react.

njlr avatar njlr commented on August 19, 2024

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?

from fable-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.