General Troubleshooting and Getting Started with React on Rails
Recently, I’ve been doing more private coaching/pairing sessions on getting setup with React on Rails. In this article, I’m going to share my general tips for maximum productivity when using React on Rails. Many of these tips will apply regardless of your programming environment.
- Do the simplest possible thing. Do not try to make all the advanced features of React on Rails, like server rendering, work at first!
- Run code that you know works. The first is just to download some code, compile it, run it, etc. To check if your machine is setup for React on Rails, git clone the React Webpack Rails Tutorial and run it!
- Start off with something that works. Then take baby steps! Add one small component. Get that one thing working first, then move on to something else.
- Read the error messages very carefully, especially the very first error message.
- Figure out the first place that something is going wrong. Ignore issues that are happening much later than the first error.
- Only run the part of the system that is causing the error. For example, if you’re having an error in the webpack compilation, run that command by itself until you resolve any errors.
- Be very careful that your installed version of software matches the documentation you are reading. Often, Github will display the latest documentation on the master branch for unreleased software. You’re probably not using unreleased software. You might switch the displayed branch to match up with what you are using.
- Check for errors in all the places where you’ll have logs. The main places to check are: 1) Output from running foreman on the console. 2) The console in the Chrome debugger. 3) Your log files for Rails.
React on Rails Specifics
- Be sure to understand simpler examples before you tackle more complicated examples. Study the output of running the React on Rails generator on a new Rails app. See the videos: React On Rails Tutorial Series. When you’ve got the basics, then see a live example at reactrails.com and its source code on github.
- Skip server rendering. Ensure that client rendering works perfectly before turning on server rendering.
- Skip hot reloading. Hot reloading allows you to see the browser update after you hit save in the editor. The alternative is to press CMD-R to refresh your browser screen. Get regular “static” loading working first. When you’re ready for hot reloading, check out the docs.
- Skip CSS Modules and creating CSS from Webpack, initially. You can do all your CSS the way you’ve always done it with Rails. When you’re ready, you’ll definitely want to consider using CSS Modules. The React Webpack Rails Tutorial uses them! Once you use them, you won’t go back!
If your time is valuable, consider signing up for a ShakaCode Coaching Plan. For $1500, you get a private Slack channel, code reviews, pairing sessions, and the support of the whole ShakaCode team. For more information, click here or email me at firstname.lastname@example.org.
Here are some of my favorite debugging articles that apply to React on Rails. You can find more by searching for debugging at forum.shakacode.com.
CEO at ShakaCode