Hello React #1: Creating a Single Page Application with React


Few days ago we were looking for a JavaScript library which is flexible and can be used in a variety of projects. Basically, something with which we can create new apps, or introduce into an existing project without rewriting it. However, we came across React, a JavaScript library for building user interfaces and AngularJS, a JavaScript MVW Framework.

Before we start creating a single page application with React we need to install NodeJS and NPM. After you have installed them, we are ready to create our first application with React.

Create React App is the best way to start building a new React single page application. So, we will be using it to create out first single page application with React.

sudo npm install -g create-react-app
create-react-app hello-world
cd hello-world
npm start

create-react-app will create a hello-world application for us with following directory structure.

hello-world/
  README.md
  node_modules/
  package.json
  .gitignore
  public/
    favicon.ico
    index.html
  src/
    App.css
    App.js
    App.test.js
    index.css
    index.js
    logo.svg

To see the application running open http://localhost:3000/. The page will reload if we make any edits in the app. Also, to run the tests just run command:

npm test

It will run the test watcher in an interactive mode.

react-blog-pic-2

At last to deploy the application, we can bundle it in production mode and optimize it for the best performance.

react-blog-pic-3

The build is minified and the filenames include the hashes. Finally, our app is ready to be deployed. Note that we have not described different components of the app yet. So, stay tuned !


KNOLDUS-advt-sticker

Advertisements
This entry was posted in JavaScript, Node.js, React, ReactJS and tagged , . Bookmark the permalink.

One Response to Hello React #1: Creating a Single Page Application with React

  1. Pingback: Hello React #2: Smallest Example in React | Knoldus

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s