4 ms·
> React has always been usable by just adding a pair of `<script>` tags to any HTML page. Yes but good luck with React.createElement(). React without JSX is re
by pier25 8y ago
> React has always been usable by just adding a pair of `<script>` tags to any HTML page.
Yes but good luck with React.createElement(). React without JSX is really a pain to use (or Preact, Inferno, etc).
Vue is much more straightforward for those simpler cases where you don't need/want to setup Babel, Webpack, etc.
- acemarke 8y agoThere's a number of options available if you don't want to use JSX. For example, if you prefer to use small wrapper functions like `h(MyComponent)` and `div()`, there's `react-hyperscript-helpers` [0]. More recently, Jason Miller published `htm` [1], which provides near-JSX syntax using ES6 template literals, and no build step required. It appears to be a very viable alternative to JSX in many ways. [0] https://github.com/jador/react-hyperscript-helpers https://github.com/jador/react-hyperscript-helpers [1] https://github.com/developit/htm https://github.com/developit/htm
- pdimitar 8y agoSure, but your claim of "you just need a pair of <script> tags" is no longer true then, is it? I can start building a house with a hammer and a shovel. Doesn't mean I can build the entire house with them alone.
- acemarke 8y agoMy claim of "you only need two script tags to write a working React app" is entirely accurate. That _does_ limit you to just `React.createElement()`, which is the core React API. If you don't want to call `React.createElement()` every time (whether or not you alias to to something like `h()`), then you either use JSX (and a build step), or one of the other options like the ones I listed. Pointing at that, and then claiming it's insufficient for "building an entire house", makes it look like there's some goalposts being shoved down the field.
- pdimitar 8y agoThe goalpost is -- and always should be -- to build a working app without pretending you don't need a ton of dependencies. You do, unless you have a much bigger time budget than most of us. We can do only so much with a limited toolset. By your analogy, we should only be able to make a working app with `document.write()`. Let's be realistic. A pair of script tags is only theoretically possible and nobody is stopping at that.
- acemarke 8y agoI never made any claims about what other tools you _might_ need to build "real world"-ish apps. I'm only saying that you don't actually need anything else, including build setups, to be able to write working React code, because that's a common misunderstanding about React. Folks assume you _have_ to have Webpack and Babel to use it.
- vinnymac 8y agoAdditionally if you find local development unpleasant you can always try remote development via something like https://codesandbox.io/ https://codesandbox.io/ which will setup a project with everything you need.
- xg15 8y agoTechnically true, but that point isn't really meaningful if the amount of tooling you realistically need to build an app keeps on growing. In theory I only need gcc, vim and a bunch of header files to write the next Chrome as well.
- tehbeard 8y agoYou know that jsx just compiles down to those calls right? Heck if all you need is just the transpile of jsx, typescript's compiler will do it just fine from the command line, no config to setup.
- pier25 8y agoObviously, but you are missing the point.
- kbp 8y ago> Yes but good luck with React.createElement(). React without JSX is really a pain to use (or Preact, Inferno, etc). What's painful about it? I prefer it without JSX, personally; JSX is a pretty simple syntax transform that doesn't really gain you anything that I can see, makes manipulating props a lot clumsier, and needs extra tooling. Most of the time it's almost identical with or without JSX, but when there is a difference, I've always found without to be smoother and clearer. You definitely want to assign React.createElement a shorter name, though.
- marcus_holmes 8y agototally agree. Not just because it's harder to use without JSX (and JSX is a great idea), but also because every Stack Overflow answer assumes you're using Webpack and JSX. For a beginner, choosing not use JSX or Webpack, etc just makes the learning cliff steeper.
- namuol 8y agoJust FYI, you can easily include a @babel/standalone script to get JSX in your script tags. https://reactjs.org/docs/add-react-to-a-website.html#quickly-try-jsx https://reactjs.org/docs/add-react-to-a-website.html#quickly...
- pier25 8y agoOh this is good! How is the browser support for this?
- acemarke 8y agoNote that running the transform in-browser on anything more than a "hello world" is going to be relatively slow. It's only useful for cases like a "single HTML file React example, with JSX syntax capability", and is _not_ recommended for any kind of production use.
- pier25 8y agoThanks, I saw that after writing my comment. It seems Vue is definitely the simpler choice to write reactive components in projects without a build chain.
- acemarke 8y agoAs I wrote up-thread, Jason Miller's `htm` library seems to be a very nice alternative to JSX that does not require a build step: https://github.com/developit/htm https://github.com/developit/htm
- pier25 8y agoThat might work in some use cases, but unfortunately tagged template literals require greenfield browsers. Vue 2 works in anything that runs ES5.
- bufferoverflow 8y ago