6 ms·
You can use React without JSX. It is especially easy if you are using CoffeeScript which makes the syntax quite terse. I personally like JSX. It is more of a v
by jasim 12y ago
You can use React without JSX. It is especially easy if you are using CoffeeScript which makes the syntax quite terse.
I personally like JSX. It is more of a variant of Javascript that lets us mix HTML into JS seamlessly. It was inspired from XHP (https://www.facebook.com/notes/facebook-engineering/xhp-a-new-way-to-write-php/294003943919 https://www.facebook.com/notes/facebook-engineering/xhp-a-ne...), a PHP extension developed and used by Facebook that lets PHP understand XML. I think that the cross-pollination of this idea into React might be one of the best things to have happened to front-end development in the recent past.
JSX is different from HTML in a few simple ways (http://facebook.github.io/react/docs/jsx-in-depth.html http://facebook.github.io/react/docs/jsx-in-depth.html):
- All HTML attributes are written in lowerCamelCase, like so: contentEditable, maxLength etc. React has a wonderful "is this what you meant?"-style warning system for when we slip-up on these details. More on HTML attributes in JSX is here: http://facebook.github.io/react/docs/tags-and-attributes.html http://facebook.github.io/react/docs/tags-and-attributes.htm...
- You can't use `class` to denote CSS class names. It is always `className`. You are going to forget this as you copy-paste a FontAwesome icon definition or Bootstrap snippet into the project and wonder what went wrong. But practice makes perfect.
- If you want to write inline styles, the style attribute should be written as a Javascript hash (it is actually a blessing in disguise). React documents it here: http://facebook.github.io/react/tips/inline-styles.html http://facebook.github.io/react/tips/inline-styles.html.
I haven't found any other incidental quirks in JSX, and it integrates nicely with Javascript in practice. It is however different from the way things have always been done, which can be a good reason for resistance.
- aikah 12y agoSure,but you need to learn JSX to read code exemples around the web.So you cant really use React without knowing JSX. That's a subtle thing but important enough when you're working on big projects.
- dandelany 12y agoSure, but if you can read HTML and you've read the above list of caveats: congratulations, you can now read JSX. The attributes are simply passed to children as props. There's really not much to it.
- dkersten 12y agoI don't think its a big deal. I use ClojureScirpt and Om, but often read React sample code (sepecially the React-bootstrap snippets). JSX doesn't map to what my ClojureScript code looks like at all, and neither does the pure JS React code, but I don't find it hard to read or understand at all and its fairly easy to learn what I need from it.