Adding a simple react component written in ruby to your Rails app

suggest change
  1. Add the hyperloop gem to the Gemfile of a Rails 4.0–5.1 app.
  2. Run bundle install.
  3. Add the Hyperloop manifest to the application JavaScript file:
// app/assets/javascripts/application.js
// ...
//= require hyperloop-loader
  1. Create React components under app/hyperloop/components:
# app/hyperloop/components/hello_world.rb
class HelloWorld < Hyperloop::Component
  after_mount do
    every(1.second) { mutate.current_time(Time.now) }
  end

  render do
    "Hello World!  The time is now: #{state.current_time}"
  end
end
  1. Components act like views. Mount one with render_component in a controller:
# somewhere in a controller:
# ...
def hello_world
  render_component # renders HelloWorld based on the action name
end

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents