Ruby on Rails - Use react_rails within our application- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
Use react_rails within your application
React.js builds
You can pick which React.js build (development, production, with or without add-ons) to serve in each environment by adding a config. Here are the defaults:
# config/environments/development.rb
MyApp::Application.configure do
config.react.variant = :development
end
# config/environments/production.rb
MyApp::Application.configure do
config.react.variant = :production
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
To include add-ons, use this config:
MyApp::Application.configure do
config.react.addons = true # defaults to false
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
After restarting your Rails server, //= require react will provide the build of React.js which was specified by the configurations. react-rails offers a few other options for versions & builds of React.js. See VERSIONS.md for more info about using the react-source gem or dropping in your own copies of React.js.
JSX
After installing react-rails, restart your server. Now, .js.jsx files will be transformed in the asset pipeline. BabelTransformer options You can use babel's transformers and custom plugins, and pass options to the babel transpiler adding following configurations:
config.react.jsx_transform_options = {
blacklist: ['spec.functionName', 'validation.react', 'strict'], # default options
optional: ["transformerName"], # pass extra babel options
whitelist: ["useStrict"] # even more options[enter link description here][1]
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Under the hood, react-rails uses ruby-babel-transpiler, for transformation.