Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Would there be an easy/straightforward way to put a jsx transpiler in front of the rust compilation step, potentially with hot reloading?

I realize that jsx in react is really just calls react.createElement, but I do think it's a very useful abstraction when you're ultimately constructing html.



The main issue is that jsx can contain both mutable references to a variable and immutable references. For example <div onClick={() => count = count + 1}>{count}</div> contains both a mutable reference to count and an immutable reference. Thus, the naive way of storing this in a single struct will fail. The use of the elm architecture (where the onClick handler returns a message, instead of directly updating count) side steps the complicated borrow-checker issues.

It is certainly possible to get around this with the proper procedural macro, but it is not easy, and will never be as "magic-free" as people want.


Look into the framework Yew. It sits somewhere between elm and react in how it's designed, and makes use of an html macro that allows for jsx-like markup.


Since Rust supports macros, I think you can actually implement most of JSX's syntax in it directly without needing an additional compiler.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: