@@ -39,6 +39,7 @@ Example app code available here: https://github.com/BookOfGreg/react-rails-examp
3939 - [ Camelize Props] ( #camelize-props )
4040- [ Upgrading] ( #upgrading )
4141 - [ 2.3 to 2.4] ( #23-to-24 )
42+ - [ Common Errors] ( #common-errors )
4243- [ Related Projects] ( #related-projects )
4344- [ Contributing] ( #contributing )
4445
@@ -56,47 +57,61 @@ https://github.com/reactjs/React-Rails/wiki
5657
5758[ Webpacker] ( https://github.com/rails/webpacker ) integrates modern JS tooling with Rails.
5859
59- Add ` webpacker ` and ` react-rails ` to your gemfile and run the installers:
60+ 1 ) Create a new Rails app:
61+ ```
62+ $ rails new my-app
63+ $ cd my-app
64+ ```
65+
66+ 2 ) Add ` webpacker ` and ` react-rails ` to your gemfile
67+ ```
68+ gem 'webpacker'
69+ gem 'react-rails'
70+ ```
6071
72+ 3 ) Now run the installers:
6173```
6274$ bundle install
6375$ rails webpacker:install # OR (on rails version < 5.0) rake webpacker:install
6476$ rails webpacker:install:react # OR (on rails version < 5.0) rake webpacker:install:react
6577$ rails generate react:install
6678```
67-
6879This gives you:
6980
7081- ` app/javascript/components/ ` directory for your React components
7182- [ ` ReactRailsUJS ` ] ( #ujs ) setup in ` app/javascript/packs/application.js `
7283- ` app/javascript/packs/server_rendering.js ` for [ server-side rendering] ( #server-side-rendering )
7384
74- Link the JavaScript pack in Rails view using ` javascript_pack_tag ` [ helper] ( https://github.com/rails/webpacker#usage ) , for example:
75-
85+ 4 ) Link the JavaScript pack in Rails view using ` javascript_pack_tag ` [ helper] ( https://github.com/rails/webpacker#usage ) , for example:
7686```
77- <!-- application.html.erb -->
87+ <!-- application.html.erb in Head tag below turbolinks -->
7888<%= javascript_pack_tag 'application' %>
7989```
8090
81- Generate your first component:
82-
91+ 5 ) Generate your first component:
8392```
8493$ rails g react:component HelloWorld greeting:string
8594```
8695
87- Your component is added to ` app/javascript/components/ ` by default.
88-
89- You can also generate your component in a subdirectory:
90-
96+ 6 ) You can also generate your component in a subdirectory:
9197```
9298$ rails g react:component my_subdirectory/HelloWorld greeting:string
9399```
100+ Note: Your component is added to ` app/javascript/components/ ` by default.
94101
95- [ Render it in a Rails view] ( #view-helper ) :
96102
97- ``` erb
98- <%= react_component("HelloWorld", { greeting: "Hello" }) %>
103+ 7 ) [ Render it in a Rails view] ( #view-helper ) :
104+
105+ ```
106+ <!-- erb: paste this in view -->
107+ <%= react_component("HelloWorld", { greeting: "Hello from react-rails." }) %>
108+ ```
109+
110+ 8 ) Lets Start the app:
111+ ```
112+ $ rails s
99113```
114+ output: greeting: Hello from react-rails", inspect webpage in your browser too see change in tag props.
100115
101116The component name tells ` react-rails ` where to load the component. For example:
102117
@@ -574,6 +589,31 @@ For the vast majority of cases this will get you most of the migration:
574589- add ` import PropTypes from 'prop-types' ` (Webpacker only)
575590- re-run ` bundle exec rails webpacker:install:react ` to update npm packages (Webpacker only)
576591
592+ ## Common Errors
593+ 1 ) While using installers.(rails webpacker:install: react && rails webpacker: install )
594+ Error:
595+ ```
596+ public/packs/manifest.json. Possible causes:
597+ 1. You want to set webpacker.yml value of compile to true for your environment
598+ unless you are using the `webpack -w` or the webpack-dev-server.
599+ 2. webpack has not yet re-run to reflect updates.
600+ 3. You have misconfigured Webpacker's config/webpacker.yml file.
601+ 4. Your webpack configuration is not creating a manifest.
602+ or
603+ yarn: error: no such option: --dev
604+ ERROR: [Errno 2] No such file or directory: 'add'
605+ ```
606+ Fix: Try updating yarn package.
607+ ```
608+ sudo apt remove cmdtest
609+ sudo apt remove yarn
610+ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
611+ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
612+ sudo apt-get update && sudo apt-get install yarn
613+
614+ yarn install
615+ ```
616+
577617## Related Projects
578618
579619- [ webpacker-react] ( https://github.com/renchap/webpacker-react ) : Integration of React with Rails utilizing Webpack with Hot Module Replacement (HMR).
0 commit comments