A framework for building reusable, testable & encapsulated view components in Ruby on Rails. (by ViewComponent)

View_component Alternatives

Similar projects and alternatives to view_component

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a better view_component alternative or higher similarity.

view_component reviews and mentions

Posts with mentions or reviews of view_component. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2022-11-24.
  • Rails 7 + Hotwire (Turbo + Stimulus) = Modern web applications
    4 projects | | 24 Nov 2022
    tl;dr; Let’s understand how we can migrate a scaffold generated by the command ‘bin/rails g scaffold Kit::Product name:string’, to an improved and performative screen. Inserting partial load and DOM manipulation writing a very little code in VanillaJS (“almost” without to write Javascript). Scaffold (Rails 7) Getting Started with Rails ( Generating the scaffold ( Using just one command you will generate all of these files: Model, Migration, Controllers, Routes, Tests, Helpers, and JSON. $ **bin/rails generate scaffold HighScore game:string score:integer** invoke active_record create db/migrate/20190416145729_create_high_scores.rb create app/models/high_score.rb invoke test_unit create test/models/high_score_test.rb create test/fixtures/high_scores.yml invoke resource_route route resources :high_scores invoke scaffold_controller create app/controllers/high_scores_controller.rb invoke erb create app/views/high_scores create app/views/high_scores/index.html.erb create app/views/high_scores/edit.html.erb create app/views/high_scores/show.html.erb create app/views/high_scores/new.html.erb create app/views/high_scores/_form.html.erb invoke test_unit create test/controllers/high_scores_controller_test.rb create test/system/high_scores_test.rb invoke helper create app/helpers/high_scores_helper.rb invoke test_unit invoke jbuilder create app/views/high_scores/index.json.jbuilder create app/views/high_scores/show.json.jbuilder create app/views/high_scores/_high_score.json.jbuilder Enter fullscreen mode Exit fullscreen mode After installing Rails, create your project, and generate your scaffold. Let's try to improve the default interface. I am using the Tailwind to insert styles on the interfaces and the ViewComponent for “creating reusable, testable & encapsulated view components, built to integrate seamlessly with Ruby on Rails”. You could see the resulting code at Turbo (heart of Hotwire) Hotwire is an alternative approach to building modern web applications without using much JavaScript by sending HTML instead of JSON over the wire. You can see the unique application’s screen in the following image. Yes, this project has just one screen. Let’s try to be simple to focus on the most important things. In this screen, we have two dynamic areas: List of products Form to create and edit the selected product I created a PR so you can see the exact part of the code that was changed or inserted to use the Hotwire on your project. You can see this PR on The unique screen on the system has a few triggers to call actions or make requests. Plus button to access the ‘kit/products/new’ page Search input field Products links to access the product’s edit page Buttons to update, remove or create products based on the form’s fields data Using the Turbo, we can override the click event of the plus button to request the HTML of a new product form from the backend and put it in the ‘product_form’ area. You don’t need to write Javascript to override the events on your elements, just insert a new attribute ‘turbo_frame’ on your HTML tag. Like here: We can use the same approach of the plus button in the link of products and prevent reloading the entire screen HTML and assets. Now we need to use a little Javascript to insert the event ‘change’ to request a filtered list of products from the backend. In my code, I insert the ‘turbo_frame’ attribute into the form to change the submit action making the request using Turbo. In the next topic, we can see how to use the Stimulus and Javascript controllers to change the event ‘change’ of the input. Now we will need to submit the form and refresh the list of products. But we can do this better. We know that the updated list has changed on the created/updated product. So, we need to update the list with this product, instead refresh and query all the list of products from the database. To do this we need to use a lot of the Javascript code or a few actions from the Stimulus. You can see about the Javascript controller in the next topic. Stimulus (modest JavaScript framework) You won’t see any difference. But the code savings and ease of integration will help you a lot when inserting new features. The objective here is to insert an event on the search input form to make a request when the user changes the input’s value. When it occurs, the system will make a request to get all products filtered by the ‘name’ column. The result will be inserted into the list after it. To implement the Stimulus in our current project, we need to follow the following steps: 1. Insert the attribute ‘data-controller=”search-list”’ to the wrapper with the form and the list of the products (app/components/search_list_component.html.erb line 1). — This attribute is responsible to relate the following code to the DIV element. Get more info here — You can use the command ‘./bin/rails generate stimulus controllerName’ to generate the Javascript file with the class definition and import it in the ‘app/javascript/controllers/index.js’ automatically. 2. Insert the attribute ‘data-search_list_target=”inputSearch”’ to the form search field (app/components/search_list_form_component.html.erb line 2). 3. Insert the action (click->search-list#selectItem) to activate the currently selected product (app/components/search_list_item_component.rb lines 20). 4. Insert the attribute ‘search_list_target=”item”’ to each item of the product list (app/components/search_list_item_component.rb lines 21). I am using to define the view components instead to use a view or partial. Pay attention to this part I really liked having this structure in my project: rails-7-fullstack/_list.html.erb at 11a479dafa5c84a1e769721d57792f39914a1204 ·… This approach is very similar to the React components or other Javascript Frameworks. I created a PR where you can see the exact part of the code I changed or inserted to use the Stimulus on my project. You can see this PR on
  • Are utility classes horrible design or am I dumb?
    5 projects | | 18 Sep 2022
    Rails has view components. GitHub started the pattern years ago in their Rails app.
  • Can anyone recommend good, free component libraries for Tailwind?
    6 projects | | 25 Aug 2022
    In Rails, I personally like to reuse a components and for that I use viewcomponents Gem ( My erb are still very verbose but I dont dupplicate the HTML.
  • GSoC 2022 CircuitVerse | Week 3 Report
    2 projects | | 2 Jul 2022
    Implement popup in form of Rails Component view.
  • Exploring ViewComponent
    3 projects | | 1 Jul 2022 ViewComponents in the Real World - Joel Hawksley Encapsulating ruby on rails view
  • view_component VS phlex - a user suggested alternative
    2 projects | 27 Jun 2022
  • RVTWS: a Ruby stack for modern web apps
    9 projects | | 24 Jun 2022
    ViewComponent provides a home for this view-related logic. This post on the Code with Jason blog explains it best. In short, ViewComponent fills a big gap in MVC architecture.
  • My project: railstart app
    47 projects | | 12 Jun 2022
  • Play with TailwindCSS in the Browser
    9 projects | | 10 Jun 2022
    This isn't meant as a contradiction of your point, but there are plenty of ways to use component-based architectures with server-side rendered apps, too, like GitHub's ViewComponent gem for Rails.

    Also, I'd go so far as to say that if you're not using a component based architecture for your web app's view layer, you're creating a ton of extra work for yourself.

  • From partials to ViewComponents: writing reusable front-end code in Rails
    11 projects | | 3 Jun 2022
    Recently, we began using ViewComponents in our project to help us build the redesigned admin section of our web. We want to share our decision process that made us try this framework in the first place and how well it went. TL;DR? We love it! ❤
  • A note from our sponsor - InfluxDB | 2 Dec 2022
    InfluxDB is the Time Series Data Platform where developers build real-time applications for analytics, IoT and cloud-native services in less time with less code. Learn more →


Basic view_component repo stats
4 days ago
Truly a developer’s best friend
Scout APM is great for developers who want to find and fix performance issues in their applications. With Scout, we'll take care of the bugs so you can focus on building great things 🚀.