

Maybe youโre a jQuery developer looking to experiment with a modern framework. Or, maybe youโre an Angular developer wanting to see what all the hype is about. Maybe youโre a seasoned back-end or systems programmer looking to make the jump to front-end. Maybe youโre new to programming in general, but want to learn how to build dynamic web applications.
Regardless of your background, youโve likely had a similar experience: React itself seems pretty straightforward, but the tooling and ecosystem is overwhelming.
You probably feel like this guy:
Iโve seen and heard variations on this theme frequently. Especially for newcomers, React development can often seem like a complex maze of tools and libraries. Even experienced developers talk about how complicated modern web dev is, and pine for the simple days of just opening an editor and writing.
Believe it or not, it is actually very simple and painless to start a new React project, thanks to amazing work by the community over the past year.
The goal of this guide is to showcase how easy it can be to start modern React development. It shares a step-by-step process, from initial system setup through to deployment, without straying into tangent explanations that arenโt critical at this point in the learning process.
No prior experience with React or its related tools is required, although it does assume that you know the basics of working with a command line and git.
This is a living document, and Iโll be updating it as the landscape changes.
Last Updated: February 28th, 2019
Yarn is a package manager. It helps us manage our projectโs dependencies.
If youโre new to programming, essentially you can think of this as a tool to help us easily download and use other peopleโs code.
Download and installation instructions are available on the Yarn site.
Once youโve installed yarn, verify that you can use it on the command line. Open a new terminal, and run:
But what about NPM?
You may have seen that NPM is the de facto package manager in the Javascript community, and may wonder why Iโm suggesting Yarn.
ย
Without getting too far off-topic, Yarn is a concerted effort by the community to improve package management. Internally it still uses the NPM package repository, so you can still install all the same packages.
Over the past couple of years, the default NPM client has improved. If youโre already comfortable with NPM, donโt worry about switching to Yarn.
ย
If youโre curious, you can read more about the differences between Yarn and NPM, but itโs not critical knowledge at this point.
When people talk about complexity in React development, often theyโre referring not to React itself, but in the build system and development environment.
They have a pointโโโas React developers, we tend to build pretty complex dev environments and build systems. We suffer this complexity because it makes React development quicker and more enjoyable.
However, that complexity is overwhelming for those just getting started, and worse, it gets in the way of learning whatโs really important: React itself.
Thankfully, there is a have-your-cake-and-eat-it-too solution. Itโs called create-react-app.
create-react-app is a command-line tool built by bright people at Facebook, and itโs amazing. It abstracts away all the complexity and difficulty of implementing Webpack, Babel, a dev server, a production build process, and a thousand other tedious-but-critical things.
Itโs zero-configuration, and doesnโt clutter up your project directory with a bunch of files you donโt understand.
Note: Eventually, you will want to spend the time learning how this works internally. Thereโs a lot of neat stuff you can do with Webpack, for example. Our top priority at the moment, though, is getting you excited about building with React, so we can defer this stuff for later.
Yarn comes with a built-in helper for using create-react-app:
yarn create react-app [your-app-name]
Iโd like my application to be named cats-n-stuff, so I can simply run:
I believe `yarn create` is available in Yarn 0.25 and higher. Try upgrading Yarn if you canโt use this command. You can also use npx create-react-app cats-n-stuff
, if youโre using NPM.
This command does quite a few things:
create-react-app
cats-n-stuff
(or whatever you name your app)Youโll notice the output towards the end gives you a set of commands.ย
Letโs start by following its directions:
Bam! If we navigate in our browser to the address provided, we see a swanky demo page:
If we open our new directory in an editor, youโll see that create-react-app has scaffolded out everything we need (and nothing superfluous).
Finally, the root directory holds stuff related to dependencies (package.json and yarn.lock), as well as a comprehensive documentation (README.md) for create-react-app.
Is this only for beginners? Will I be handicapping myself down the line?
create-react-app abstracts away all configuration, to help you focus on writing the application itself. At some point, though, you may want to access that configuration.
ย
Thankfully, create-react-app has an eject feature that removes this abstraction and exposes the underlying configuration. This means that create-react-app is a brilliant tool not just for newcomers, but also for experienced React devs.
ย
Iโve been using React for years, and I use create-react-app on all new side projectsย :) I try to go as long as I can without ejecting.
Ok, weโre looking pretty good here! In less time than it takes to write up an HTML template, weโve scaffolded out an entire front-end project.
Now we just have to, you know, write our actual application.
Start with just React.
If you follow many of the tutorials intended for intermediate or advanced users, you may think you need to learn about and install a dozen โsupplementaryโ packages. After all, React is just the view layer, right?
Wrong. Facebook used to say that React was the โVโ in โMVCโ. They stopped using that language, because it isnโt true; React is an entirely different paradigm, not simply a template renderer. The truth is that React is surprisingly capable on its own.
For example, the most critical package people typically recommend is React Router. Even the most trivial app will need some kind of routing built-in, so clearly weโll need to use it in our first application, right?
Well, first of all, I believe the best way to learn is to make several small โweekend projectโ applications. Those types of applications donโt often need more than a single route: your goal is to build something quick and neat in React, do you really need a bunch of different pages? Start small, work your way up to more complex projects.
Additionally, there is tremendous educational value in learning how to solve these kinds of problems yourself. Why not try to implement your own basic router? The React API is powerfulโโโReact Router is still just React, after all!
You may discover, after your second or third small React project, that certain things are more painful than youโd like. Maybe your homegrown router is proving to be too much trouble, or maybe you feel like your applicationโs state is hard to manage. This is when you should be searching for pre-existing solutions; after youโve encountered the problem, not before.
Spend time learning React on its own. Add dependencies as you need them. Try to solve problems yourself; if nothing else, youโll understand the benefits of things like Redux or React Router.
After spending some time googling for React tutorials, Iโve realized exactly why newcomers find React so confusing.
Itโs actually pretty tough to find reliable, up-to-date tutorials that cover just React, without delving into webpack and redux and a million other things.
Here are the resources Iโve found that do the job:
Alright, youโve built an awesome little toy app. Now you want to show your creation to the world. How do we get this thing online?
Web development is fun, and itโs even better when you wind up with something neat to show off. Thereโs an incredible amount of satisfaction achieved by showing the world your random side projects.
The first thing weโll need to do is build our project.
What does this do?
`build` is an NPM script provided by create-react-app. It bundles up your code into ready-to-deploy static files. If you check the โbuildโ directory in your project, youโll see what it generates.
As with everything else in modern web development, there are a bunch of options for how to actually get your built files onto the internet.
Create-react-appโs documentation covers several possible deployment options, and in my experience, Surge.sh is the quickest, simplest way to get code online quickly.
Letโs install it with Yarn:
We install it globally so that we can use its CLI tool. Letโs run it now:
Running surge will walk us through the deployment process. Enter an email and password to create a new account.
The third step, project path, is important. It should auto-fill the current location, but youโll need to add /build to the path, so that it knows to serve only the built project files, and not the source files.
Once you enter these 3 fields and select a domain for your project to live at, Surge does all the work to get it online.
Amazingly, this is all we have to do. If we go to our supplied domain, we see our project:
If we wanted to, we could just repeat this process every time; build, run surge, and then specify a project path and domain name.
We can use NPM scripts to be a little fancy though. Add this line to your package.json, under โscriptsโ:
"deploy": "yarn run build && surge -p build -d your-domain.surge.sh"
Terminal commands can be stringed together with &&
, and so we can create a single NPM script to do all the stuff we need. We build a fresh copy of our project, and then deploy it with Surge, pre-filling some of the required fields.
This command starts by building the latest version of our project, and then invoking Surge with some default arguments. Hereโs my package.json, with the deploy script:
Now, all we have to do is run a single command, and in under 20 seconds, our glorious project is up for anyone to see.
There are two misconceptions that newcomers often have about React:
I hope Iโve done a good job disproving these theories. You can get started in seconds building a glorious front-end web application, and you can start without any extra dependencies.
By far the most popular community hub for React developers is Reactiflux. Itโs a great place to meet React developers, and get help if you find yourself stuck or confused.
For myself personally, Twitter has been an amazing source to learn more about React and meet the community. Dan Abramov, a member of the React core team and co-creator of Redux, has a great list of people to follow.
Also, Facebook maintains a list of React conferences. Speaking from experience, React conferences are awesome.
Thanks forย reading!
Iโm keen to hear your feedback on this article! Anything I could do to make it more beginner-friendly? Let me know onย twitter.
Finally, if you found this post helpful, please give it a recommendation by clicking the clap icon down thereย :)
Create your free account to unlock your custom reading experience.