Ad

React .js.jsx Extension In Ruby On Rails Application

Currently in one of project which is using React on the front-end and Ruby on Rails on the back-end I can see .js.jsx files for all React-related logic. It's a bit confusing for me, because I'm used for React to see only .js or .jsx file extensions.

Is there any reason why Ruby on Rails would use .js.jsx? I'm not into Ruby world at all, therefore it's my only one guess why it should be like that. Or it's simply a developer mistake to do so?

Ad

Answer

People, who use react-railsgem can use .js.jsx extension due to ability of this gem (library) to compile it to clean js code without external build step. Accordingly to documentation:

When you name your file with myfile.js.jsx, react-rails will automatically try to transform that file. For the time being, we still require that you include the docblock at the beginning of the file. For example, this file will get transformed on request.

/** @jsx React.DOM */
React.renderComponent(<MyComponent/>, document.getElementById('example'))
Ad
source: stackoverflow.com
Ad