Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React.js and jsx over ejs?

What do react.js and jsx respectively allow you to do that ejs doesn't? For what use cases would one employ one or the other. Are they mutually exclusive? Can they be used in combination?

like image 503
Kinnard Hockenhull Avatar asked Feb 26 '16 19:02

Kinnard Hockenhull


1 Answers

JSX and EJS are indeed both templating languages, however that's sort of where the similarities end. JSX is Facebook's offering to the JS world to make writing views with your React components simpler and more efficient (you can learn more about JSX here).

To answer your questions in order:

  1. ReactDOM, React and the JSX templating language are a suite of tools to make writing javascript view code more pleasant and more performant by using a complex difference engine to calculate when DOM reflows are necessary. EJS is similar to the JSX part of this equation, but cannot talk to your React components.

  2. You would use JSX to write what your React components should return to the DOM in a friendlier, more readable way then what would be ordinarily written.

  3. They could be used in combination, but it would be a long, pointless, up-hill battle to get them to talk to one another not to mention you would have to build a translator to get the EJS templates to be understood by React and ReactDOM. I wouldn't try it.

I assume you're embarking on your React journey... Welcome! At first things will be confusing, but keep digging. Once you get the basics, React development is a lot of fun and there's a great community surrounding the libraries.

like image 155
David Hariri Avatar answered Sep 24 '22 04:09

David Hariri