Skip to content
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 jsx string template support to default template and to docs? #571

Open
jkone27 opened this issue Mar 29, 2023 · 1 comment
Open

Add jsx string template support to default template and to docs? #571

jkone27 opened this issue Mar 29, 2023 · 1 comment

Comments

@jkone27
Copy link

jkone27 commented Mar 29, 2023

https://fable.io/blog/2022/2022-10-12-react-jsx.html

i saw this post and was able to have it working, i think is a cool feat especially for js devs, not familiare with typed HTML, i think is quite nice to add!

very cool, and the new template is amazing :)

i had to add just this 2 in the template , maybe Fable.Core is not required as it's already upgraded?

<PackageReference Include="Feliz.CompilerPlugins" Version="2.2.0" />
<PackageReference Include="Fable.Core" Version="4.0.0-theta-006" />

then i was able to do for example

[<AutoOpen>]
module JsxHelpers =

   let inline toJsx (el: ReactElement) : JSX.Element = unbox el
   let inline toReact (el: JSX.Element) : ReactElement = unbox el

type Components =

   [<ReactComponent>]
   static member HelloWorld() = 
       JSX.jsx $"""
       <>
       <h1>HELLO WORLD!</h1>
       <div>this is a div from JSX</div>
       </>
       """
       |> toReact
@Zaid-Ajaj
Copy link
Owner

very cool, and the new template is amazing :)

Thank you! 😄

Add jsx string template support to default template and to docs?

Could add it to the docs but not sure if I should it yet to the template itself because I feel like it is still experimental. Also the fact that you need toJsx and toReact is a bit hacky. There is the choice between [<ReactComponent>] and [<JSX.Component>] but could introduce some confusion for beginners

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants