You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-10Lines changed: 59 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,13 +58,11 @@ Alternatively, you can include it directly as a separate script tag:
58
58
59
59
### JSX
60
60
61
-
To transform your JSX into JS, simply create `.js.jsx` files, and ensure that the file has the `/** @jsx React.DOM */` docblock. These files will be transformed on request, or precompiled as part of the `assets:precompile` task.
61
+
To transform your JSX into JS, simply create `.js.jsx` files. These files will be transformed on request, or precompiled as part of the `assets:precompile` task.
62
62
63
-
CoffeeScript files can also be used, by creating `.js.jsx.coffee` files. You must use this form of the docblock at the top of each file: `###* @jsx React.DOM ###`. We also need to embed JSX inside backticks so CoffeeScript ignores the syntax it doesn't understand. Here's an example:
63
+
CoffeeScript files can also be used, by creating `.js.jsx.coffee` files. We also need to embed JSX inside backticks so CoffeeScript ignores the syntax it doesn't understand. Here's an example:
64
64
65
65
```coffee
66
-
###* @jsx React.DOM ###
67
-
68
66
Component=React.createClass
69
67
render:->
70
68
`<ExampleComponent videos={this.props.videos} />`
@@ -73,10 +71,10 @@ Component = React.createClass
73
71
74
72
### Unobtrusive JavaScript
75
73
76
-
`react_ujs` will call `React.renderComponent` for every element with `data-react-class` attribute. React properties can be specified by `data-react-props` attribute in JSON format. For example:
74
+
`react_ujs` will call `React.render` for every element with `data-react-class` attribute. React properties can be specified by `data-react-props` attribute in JSON format. For example:
77
75
78
76
```erb
79
-
<!-- react_ujs will execute `React.renderComponent(HelloMessage({name:"Bob"}), element)` -->
77
+
<!-- react_ujs will execute `React.render(HelloMessage({name:"Bob"}), element)` -->
This is not suitable for ReactJS props, which is expected to be a key-value object. You will need to wrap your index.json.jbuilder node with a root node, like so:
React components can also use the same ExecJS mechanisms in Sprockets to execute JavaScript code on the server, and render React components to HTML to be delivered to the browser, and then the `react_ujs` script will cause the component to be mounted. In this way, users get fast initial page loads and search-engine-friendly pages.
@@ -136,8 +189,6 @@ In order for us to render your React components, we need to be able to find them
136
189
This will bring in all files located in the `app/assets/javascripts/components` directory. You can organize your code however you like, as long as a request for `/assets/javascripts/components.js` brings in a concatenated file containing all of your React components, and each one has to be available in the global scope (either `window` or `global` can be used). For `.js.jsx` files this is not a problem, but if you are using `.js.jsx.coffee` files then the wrapper function needs to be taken into account:
137
190
138
191
```coffee
139
-
###* @jsx React.DOM ###
140
-
141
192
Component=React.createClass
142
193
render:->
143
194
`<ExampleComponent videos={this.props.videos} />`
@@ -257,8 +308,6 @@ end
257
308
It is possible to use JSX with CoffeeScript. The caveat is that you will still need to include the docblock. Since CoffeeScript doesn't allow `/* */` style comments, we need to do something a little different. We also need to embed JSX inside backticks so CoffeeScript ignores the syntax it doesn't understand. Here's an example:
0 commit comments