Skip to content

1 intro

Ben Foley edited this page Aug 9, 2019 · 13 revisions

Introduction to React

  • TODO: write something about what's so great about React?
  • Also TODO: Comparisons with other systems?

Installation

For OSX

  1. Homebrew is a program that we use to install other programs. Go to the Homebrew site https://brew.sh and copy the line of code from the Install Homebrew section.

  2. Open a Terminal window, paste the line you just copied and press Return. Follow the prompts to continue the installation.

  3. Install Node by running the following command in the terminal. (Run means copy the line below, paste it into terminal, press Return.) Installing Node also installs npm, a package manager specifically of Javascript packages used by Node.

brew install node
  1. When it looks like it's done, check that Node and npm installed OK by running these commands. You should see some version numbers, e.g. v10.15.3. Do them one line at a time.
node -v
npm -v
  1. Set yourself as an owner of your ~/.npm and /usr/local/lib/node_modules directories by running these two commands. You'll be asked for your computer user account password:
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules
  1. Install Yarn, another package manager!
brew install yarn
  1. Ready to go!

For Windows

  1. Download the Windows LTS installer from the Node web site.

  2. Run the installer (the node-vxxx.msi file you downloaded in the previous step.) It may require your computer's administrator privileges.

  3. Follow the prompts in the installer, accept the license agreement, click the OK/Next button as required and accept the default installation settings.

  4. When it looks like its done, open the Command Prompt terminal. Verify the installation has succeeded, by running the following commands to check the version number of node and npm. Run means copy the line below, paste it into terminal, press Return. Do them one line at a time.

node -v
npm -v
  1. Run this command in the terminal to update the version of npm that the Node installer provided.
npm install npm --global
  1. Install yarn, another package manager, by downloading the installer from the Yarn site. Follow the prompts to install it.

  2. Ready to go!


Create an app

We can use an npm package called create-react-app to create a basic React project. Create-react-app will make a folder with a name we give it, and download Javascript packages (including the React ones) and some template files into that folder. We will edit the template files to build our app.

Some housekeeping first, think about where you want to keep your projects on your computer. One approach is to put a "sandbox" folder somewhere - your Desktop, or user home folder. Here's how to make a sandbox folder in your home folder using the command line, and navigate there.

mkdir ~/sandbox
cd ~/sandbox

Now we are in the sandbox folder, create the app:

npx create-react-app my-app

Once it is done, change into the project folder and start the app.

cd my-app
yarn start

This launches a hot reloading server and shows the app in the browser. Hot reloading means we can make changes to the code and the browser will update automatically without us needing to reload.

Clone this wiki locally