Skip to content

Installation

Add ReactiveComponent and its dependencies to your Gemfile:

gem "reactive_component"

Then install:

Terminal window
bundle install

Add the engine to your config/routes.rb so the server-action endpoint is available:

Rails.application.routes.draw do
mount ReactiveComponent::Engine => "/reactive_component"
# ... your other routes
end

This mounts a single POST /reactive_component/actions endpoint used by live_action to execute server-side actions securely.

If your application uses importmap-rails, ReactiveComponent automatically registers its import map pins when the engine loads. The engine pins all files under app/javascript/reactive_component so they are available to the asset pipeline.

You need to register the Stimulus controller in your application. In your JavaScript entrypoint (e.g. app/javascript/controllers/index.js), import and register the controller:

import { application } from "controllers/application"
import ReactiveRendererController from "reactive_component/reactive_renderer_controller"
application.register("reactive-renderer", ReactiveRendererController)

If you are using esbuild, Vite, or another bundler, you can import the controller from the gem’s app/javascript directory. Add the gem’s JavaScript path to your bundler’s configuration and import the controller as shown above.

ReactiveComponent requires ActionCable to be configured and running. Make sure your config/cable.yml is set up (Redis is recommended for production) and that ActionCable is mounted in your routes:

config/routes.rb
Rails.application.routes.draw do
mount ActionCable.server => "/cable"
mount ReactiveComponent::Engine => "/reactive_component"
end

ReactiveComponent depends on the following gems (declared in the gemspec):

GemVersionPurpose
rails>= 7.1Framework
view_componentanyBase component library
turbo-railsanyStream signing and Turbo integration
ruby2jsGitHub HEADERB-to-JavaScript template compilation
prismanyRuby source code parsing for ivar extraction