Here are a few highlights. For the full list, see the changelog!
Webpacker was great to work with.
react-rails now supports webpacker for:
- Mounting components with
<%= react_component(...) %>via
- Server rendering from a webpacker pack (
- Installation and component generators
A nice advantage of using webpacker is that you can load React.js from NPM instead of the
react-rails gem. This way, you aren’t bound to the React.js version which is included with the Ruby gem. You can pick any version you want!
UJS on npm
To support frontends built with Node.js,
react-rails’s UJS driver is available on NPM as
react_ujs. It performs setup during
require, so these two are equal:
1 2 3 4 5
Request-based prerender context
If you’re prerendering your React components on the server, you can perform setup and teardown in your Rails controller. For example, you might use these hooks to populate a flux store.
First, add the
per_request_react_rails_prerenderer helper to your controller:
1 2 3 4
Then, you can access
react_rails_prerenderer in the controller action:
1 2 3 4 5 6
That way, you can properly prepare & clean up a JS VM for server rendering.
ReactRailsUJS “automatically” detected which libraries you were using and hooked up to their events for rendering components.
It still checks for libraries during its initial load, but you can also re-check as needed:
This function removes previous event handlers, so it’s safe to call anytime. (This was added in
See the changelog for bug fixes and a new default server rendering configuration.
Webpacker is great! Setup was smooth and the APIs were clear and convenient. I’m looking forward to using it more.
🍻 Here’s to another major version of