Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Thinking in Components: Building Reusable UIs i...

Thinking in Components: Building Reusable UIs in Rails with ViewComponent

Avatar for Prabin Poudel

Prabin Poudel

November 09, 2025
Tweet

More Decks by Prabin Poudel

Other Decks in Programming

Transcript

  1. Building Reusable UIs in Rails with ViewComponent Thinking in Components

    Prabin Poudel Ruby on Rails Consultant & CEO @ Truemark Technology
  2. @coolprobn @coolprobn Prabin Poudel 👋 Ruby on Rails Consultant &

    CEO @ Truemark Technology prabinpoudel.com.np
  3. Rails view convention The problem with raw views Enter ViewComponent

    Example: Building a Form Field Example: Building a Button Benefits of ViewComponent Q&A Agenda
  4. Repetition of code Hard to maintain consistency across the app

    Code Spaghetti Difficult to preview in isolation Problems with Raw Views
  5. https://viewcomponent.org/ A framework from GitHub to build encapsulated, reusable view

    objects Think of it as React components, but for Rails views Each UI piece = a Ruby class + a template Example: following command generates two files app/components/button_component.rb app/components/button_component.html.erb Enter ViewComponent
  6. Preview like Action Mailer previews Create a file named `test/components/previews/button_component_preview.rb`

    Visit /rails/view_components to view all previewable components Easy to Preview in Browser