When I was first learning React I went through about 17 tutorials before I finally grokked what it was all about. Which is weird because React is quite simple really.
I’m gonna build the tutorial that I wished I’d had when I started learning it.
Let’s do this.
But “Do what?” you may ask?
We are going to build a blogging platform. It’s going to be Rails on the back end and React on the front end. We’re going to test with Minitest, Jest and Enzyme as we go along. We’ll deploy it on Heroku. We’ll use CircleCI for continuous integration.
We are not going to use Redux. I have an idea for a more object-oriented state management system that leverages the rich metadata that Rails already has and, hopefully, avoids all the acres of boilerplate code that every other React tutorial seems to generate. I don’t have a design for this in mind. I’m hoping one will emerge as we go along.
Let’s start with a quick planning session. What do we want our blogging platform to do?
- An author can publish a blog post.
- A reader can read a blog post.
- The home page shows a list of posts, most recent first.
- An author can edit a blog post.
- Readers can comment on a post.
- Comments are held for moderation.
- The author can approve comments.
- Notify the author when there are comments.
At some point we’ll want to upload images and have multiple authors and fancy formatting and RSS feeds and other blogphernalia but that list is enough to get us started.
I’ll tackle the second story first because I like to get something working from end to end as quickly as possible and reading a post has fewer moving parts than creating one.
Join me here to get started.
I’ll add links to all the episodes here for folks who want to skip ahead.
- Install Rails, Yarn, React & create a project on GitHub.
- Create a Post model in Rails and show the JSON.
- Introducing React components.
- Testing React with Jest & Enzyme. Setup CircleCI.
- Introduce class components and load a post from the server.
- Mock the API call to the server.
- Add a test helper to make testing React components easier.
- Create a new post in our PostsController.
- Use a controlled form to create a new post.
- Connect our new form to the back end to create a post.
- Fetch a list of posts from the server.
- Testing asynchronous components.
- Managing state in a React application.
- CHECKPOINT: Review the plan.
- Add a user model for registration and sign in.
- Deploy to Heroku.
- Extract our ReactToRails library to eliminate some boilerplate.
- Use the ReactToRails library to build the CRUD for users.