@@ -46,11 +46,11 @@ $ rails generate react:install
46
46
47
47
This gives you:
48
48
49
- - ` components/ ` directory for your React components
50
- - [ ` ReactRailsUJS ` ] ( #ujs ) setup in ` packs/application.js `
51
- - ` packs/server_rendering.js ` for [ server-side rendering] ( #server-side-rendering )
49
+ - ` app/javascript/ components/` directory for your React components
50
+ - [ ` ReactRailsUJS ` ] ( #ujs ) setup in ` app/javascript/ packs/application.js`
51
+ - ` app/javascript/ packs/server_rendering.js` for [ server-side rendering] ( #server-side-rendering )
52
52
53
- When you add a component to ` components/ ` , you can [ render it in a Rails view] ( #view-helper ) :
53
+ When you add a component to ` app/javascript/ components/` , you can [ render it in a Rails view] ( #view-helper ) :
54
54
55
55
``` erb
56
56
<%= react_component("HelloWorld", { greeting: "Hello" }) %>
@@ -78,6 +78,16 @@ var ReactRailsUJS = require("react_ujs")
78
78
ReactRailsUJS .useContext (myCustomContext)
79
79
```
80
80
81
+ ### Gotcha: Capitalization
82
+
83
+ Component File Name | ` react_component ` call
84
+ -----|-----
85
+ ` app/javascript/components/samplecomponent.js ` | ` react_component("samplecomponent") `
86
+ ` app/javascript/components/sample_component.js ` | ` react_component("sample_component") `
87
+ ` app/javascript/components/SampleComponent.js ` | ` react_component("SampleComponent") `
88
+ ` app/javascript/components/SampleComponent.js.jsx ` | Has to be renamed to SampleComponent.jsx, then use ` react_component("SampleComponent") `
89
+
90
+
81
91
## Use with Asset Pipeline
82
92
83
93
` react-rails ` provides React.js & a UJS driver to the Rails asset pipeline. Get started by installing:
0 commit comments