3 ms·
> Do you mean that before JSX could be compiled to createElement and some other library's createElement could be used? If so I would ask how often does that act
by lucideer 6y ago
> Do you mean that before JSX could be compiled to createElement and some other library's createElement could be used? If so I would ask how often does that actually happen?
Yes, this is quite common practice. Many non-React libraries support this, but it's also extremely easy to use with your own templating function (the implementation can be as little as 1 line long)
> I would assume that any library that wanted to consume JSX would have their own JSX parser and compile to whatever structure that library wanted?
Nope, this isn't how JSX works. For example, React does not contain a JSX parser. JSX syntax is transpired by a build tool: currently the two most popular build tools are TSC and Babel. Both support targeting a custom library or your own custom code instead of React (but only the function name can be customised, the function signature that JSX is transformed to, as discussed in this article, is not customisable)
- bryanrasmussen 6y agoOk thanks, goes against my assumptions of how I would implement a JSX consuming library, but I guess there are probably lots of good reasons (performance, less code) why people do it this way and, as can happen, my assumptions probably wouldn't stand the test of actual implementation.