
May 2, 2025
In recent years, many Ruby and Ruby on Rails projects have adopted React for their front-end needs. Whether you’re building a modern single-page application (SPA) or just enhancing parts of your Rails views, learning React can open up a new world of interactivity and frontend control.
This article is my first step into React, with a simple yet complete “Hello World” application β containerized using Docker. It sets the stage for building more complex, production-ready apps that can integrate smoothly with a Rails API backend.
π The Stack
- React: UI Library for building components
- Node.js (Alpine): Lightweight base image
- Docker & Docker Compose: To isolate and run our app consistently
- No Create-React-App CLI involved: We manually set up and understand each part
π¬ Need to Add a React Frontend to Your Ruby or Ruby on Rails Project?
I specialize in Ruby and Ruby on Rails development, and I’m currently diving deep into React to build modern, interactive frontends.
If youβre looking to integrate a React UI with your Rails API or modernize an existing project β letβs talk!
π Get in touch via Ruby Stack Newsπ§± Project Structure
my-react-app/ βββ Dockerfile βββ docker-compose.yml βββ package.json βββ public/ β βββ index.html βββ src/ βββ index.js
π¦ package.json
We’re using react, react-dom, and react-scripts to bootstrap the project.
{ "name": "frontend", "version": "1.0.0", "dependencies": { "react": "^18.0.0", "react-dom": "^18.0.0", "react-scripts": "5.0.1" }, "scripts": { "start": "react-scripts start" } }
π§ Dockerfile
This sets up the React app using a Node.js Alpine image:
FROM node:current-alpine3.20 WORKDIR /app COPY package*.json ./ RUN npm install COPY . . EXPOSE 3000
π³ docker-compose.yml
We use Docker Compose to streamline development:
services: react-app: build: context: . dockerfile: Dockerfile ports: - "3000:3000" volumes: - .:/app environment: - NODE_ENV=development stdin_open: true tty: true
π‘ The App
src/index.js contains the simplest React example: a component that greets the world.
function Greeting({ name }) { return <h1>Hello, {name}</h1>; } export default function App() { return <Greeting name="world" />; }
The component is rendered into the div#root of public/index.html.
π§ͺ Run It
To get this up and running:
docker-compose up --build
Then visit http://localhost:3000 to see: Hello, world
π± Whatβs Next?
This tiny app is just the first kick in building a complete frontend for a Rails API. Future steps could include:
- React Router for client-side routing
- Fetching data from a Rails backend
- Managing state with Redux or Context
- Deploying via Nginx + multi-stage Docker builds
π§ Final Thoughts
As a seasoned Ruby developer, learning React adds another powerful tool to your stack β especially in the API + SPA architecture that’s become so common.
This “Hello World” is a great starting point, and Iβll be sharing more steps soon as I build a full-featured app from here.
Follow along and feel free to clone the repo, tweak, or ask questions! π
