5 ms·
Something I wish is that you could "render" JSX agnostically and just get a JSON data structure describing a tree of tags, which is not specific to the platform
by brundolf 1y ago
Something I wish is that you could "render" JSX agnostically and just get a JSON data structure describing a tree of tags, which is not specific to the platform or even the framework, and then you could pass that off to whichever subsystem for whichever purpose (or even serialize it or send it over a wire). We wouldn't need separate build plugins for each JSX-using framework, you'd just pass them your data
- vmg12 1y agoYou can build your own jsx renderer and get exactly that, it's not that difficult.
- brundolf 1y agoRight, but only with a custom transpilation step. It would be nice if there were only a single standard JSX transpilation that all the frameworks and platforms ingested the output of
- whstl 1y agoIt kinda is! The only difference between JSX transpiler outputs is the factory function (and the Fragment component). For React the factory function it's `React.createElement`, for Preact it's `h`. Babel has a pragma property, and esbuild allows you to pass it in the command line: `--jsx-factory=h`. https://esbuild.github.io/content-types/#auto-import-for-jsx https://esbuild.github.io/content-types/#auto-import-for-jsx
- brundolf 1y agoI knew it transpiled to a function call, though I didn't know babel lets you parameterize that without writing a custom plugin
- atoko 1y agoHello! One of the main challenges of figuring a JSX syntax out is what to do about the “children” prop. Experientially, typescript still has a bit of trouble figuring out the right types for these nested structures. Even with a typed jsx function it sometimes doesn’t infer correctly, so providing plugin capability would take a very careful hand
- williamdclt 1y agoJSX parameters aren’t necessarily serialisable though?