You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/blog/2022/2022-05-31-Snake_Island_alpha.md
+142-1Lines changed: 142 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,8 +50,149 @@ You can track the current progress for Dart compilation [here](https://github.co
50
50
51
51
## JSX
52
52
53
-
...
53
+
Fable JS wasn't supposed to get any new feature with Snake Island, but at the last minute we've implemented support for yet another language or, more exactly, a language-in-a-language. [JSX](https://reactjs.org/docs/introducing-jsx.html) was introduced by the React team as a way to declare HTML-like UIs directly in JavaScript without the need of a template language. Although Fable has supported React from the start, it never used JSX. Instead it directly output the JS code generated by JSX templates. This made sense because for React JSX was only syntax sugar and this way we could save a compilation step.
54
+
55
+
However, given the popularity gained by JSX, there are now tools that take advantage of this compilation step to perform code analysis or other operations. Like [SolidJS](https://www.solidjs.com/) which uses JSX to analyze the dependency tree in your code and translate the declarative render functions into surgical imperative updates that don't need a Virtual DOM and are smaller and faster than equivalent React apps (while maintaining the same developer experience overall). We have already implemented a [Feliz](https://zaid-ajaj.github.io/Feliz/)-like API to create Solid apps with good results. For example, the following code:
Your nice, declarative code has been magically transformed into performant imperative instructions :)
164
+
165
+
Soon JSX will be available to Fable React apps too! Though as commented above, it won't make a big difference in React (and in fact it can be more limiting as JSX needs to be interpreted statically, so list comprehensions for example can be trickier) but we are also introducing JSX templates which can be particularly helpful when bringing external HTML code to your app. And with the [F# template highlighting VS Code extension](https://marketplace.visualstudio.com/items?itemName=alfonsogarciacaro.vscode-template-fsharp-highlight) you can achieve a very similar experience to [Fable.Lit](https://fable.io/Fable.Lit/).
166
+
167
+
```fsharp
168
+
let gradient, setGradient = React.useState(5)
169
+
170
+
Html.fragment [
171
+
Html.div [
172
+
Html.input [
173
+
Attr.typeRange
174
+
Attr.min 1
175
+
Attr.max 100
176
+
Attr.value $"{gradient}"
177
+
Ev.onTextInput (fun (value: string) -> value |> int |> setGradient)
Sorry but this browser does not support inline SVG.
191
+
</svg>
192
+
"""
193
+
```
54
194
195
+
Basically this means you'll be able to write JSX code directly into your F# app! And you can try it out already with Solid and Snake Island by cloning [this repo](https://github.com/alfonsogarciacaro/Feliz.Solid).
0 commit comments