Can we use React with JSX in browser without any compiler using this? I'm sure people have tried it but I can't find it. I just want an `index.html` file that I can write React code in it and play around with things...
React is already often slow enough. Pushing compilation steps to the client is inefficient, especially when you consider that JSX compiles to basic functions and you could have used those functions since the first version.
That has been possible for some time with Babel[0] and was also referenced in the old React docs[1]. But, as stated there and in the sibling comment here, it's not really suitable for production use.
From the react docs: "it makes your website slow and isn’t suitable for production"
I don't really like blanket statements like this or think they are appropriate. It's so counter to the spirit of the web.
Like, what does 'slow' mean in an absolute statement like this? It depends entirely on the system and usecase. It's just code at the end of the day. If it works for you, go for it!
It's interesting that this is your perception of "the spirit of the web" whereas other people are going to say that requiring JavaScript at all is "counter to the spirit of the web".
They are many libraries that use tagged template string to allow this, the most interesting to my eyes is the one made by preact dev. It's just named htm [0], it's made by preact but it can totally be used with react.
The most interesting thing of this one is that uses no custom syntax for js variable, so @attribute something when you must pass an object as props.
You can import the Fragment component of the React package or stack them directly, it works too.
Normally, the empty bracket syntax should work, they have a few issues closed and open that talk about it in their repo.
JSX expressions are compiled to calls of JSX(tag,atts,kids) function. That function can be redefined enabling
different libraries to use JSX in the way they want, here is an example of using JSX with PReact:
import { h, render, Component } from 'preact';
JSX = h; // let's use PReact::h() as a driver of JSX expressions