Skip to main content

React - setup and getting started

As per React website, It is a declarative, flexible, and efficient JavaScript Library for web user interface development.

In this tutorial, we will learn how to get started with this framework and at the end of it, we will be able to set up, run and test a basic text displayed in the browser.

Tools & Libraries used:

  1. React 16.x
  2. NodeJS 6.x
  3. NPM 5.x

Note: This tutorial was tested on a Mac OS V10.13 machine. For developers using windows machines, command syntax will change a bit.

Initial setup

We need NodeJS 6.x and NPM 5.x installed in the build pipeline of React project. See reference section to know more about installing these prerequisites.

From scratch

When we are starting a single-page web project from scratch, we should use NPM or NPX toolchains to get the skeleton code and run the project in development mode.

$ sudo npm install -g create-react-app $ create-react-app 01-getting-started

Previous commands create a standard React project structure with required files to build and run the single page application in the development phase. Understand, it just provides you a bare minimum structure, we are the ones who extend it with best practices to manage our source code in a more structured way.

NodeJS single page app project structure

src folder keeps JavaScript files. the public folder has an HTML file.

Before going ahead, let's start the local development server to check out how the default app looks.

$ cd 01-getting-started $ npm start

It will build the project and start a local web server on port 3000, and it looks like it. We will add more details further.

 ReactJS default app landing page

An existing project

We don't need to make much change in the existing project structure to use React in that. Try to React in a standalone component first to get started and slowly extend it further.

Using npm to install react dependencies in an existing project

npm install --save react react-dom

We can also include react js files in the HTML file directly like it. (We are using CDN hosted js files)

<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<br>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>

ES6 and JSX

We recommended using React with babel to enable ES6 and JAX support. These improve development efficiency.

Introducing JSX

React provide core JavaScript based syntax to define UI element. Though JSX is a syntax extension to JavaScript, more elegant and effective way to define UI elements.

Let's say we have to display Hello World text inside a paragraph. See how we can do it in plain JS and JSX.

const pElement = React.createElement('p', null, 'Hello World');

const pElement = <div>Hello World</div>;

Well JSX syntax looks very similar to the scripting language syntax, but it is very powerful, which we will see further in React tutorial series.

We recommend that JSX create a UI element.

References

  1. Introduction
  2. NPM & Front End Packaging
  3. Webpack module bundle concepts
  4. NodeJS and NPM installation guide
  5. Babel for enabling ES6

Comments

Popular posts from this blog

Extend and reuse an existing AirByte destination connector

AirByte is an open-source ELT (Extract, Load, and Transformation) application. It heavily uses containerization for the deployment of its various components. On the local machine, we need docker to run it. AirByte has an impressive list of source and destination connectors available. One of my use case data destinations is the  ClickHouse data warehouse and its destination connector is not yet (2021-12-08) available. As per the documentation, It seems that creating a destination connector is a non-trivial job. It's a great idea to build an open-source ClickHouse destination connector. However, I tried avoiding the temptation to create one because of the required effort. AirByte has a  MySql destination connector available. ClickHouse provides a MySQL connector for access from any MySQL client. We need to configure Clickhouse to give support for the MySQL connector. Accessing ClickHouse from AirByte using its MySQL destination connector looks promising. However, when ...

Understanding Type Checking

A few examples of types in the context of programming language can be integer, float, character, string, array, etc.  When a program executes then data flow between instructions and values of specific types are assigned to a variable after some operation. It's important for the system to verify if the correct types are used as operands in operations. For e.g. In a sum operation, the expectation for operands to be of numeric type. The program's execution should fail in the case there is inconsistency. We can classify programming languages into two categories based as per their ability to cater to type safety: Dynamically Typed Language Statically Typed Language

Setting Clickhouse column data warehouse at Google Cloud Compute Engine VM

I didn't have a Google Cloud account associated with my email, so I signed up for one. It needs a valid Credit Card and mobile number to check if you are human. On successful sign up I get 300$ to spend within 3 months. Creating a free forever Google Cloud Compute Engine VM As per Google Cloud documentation you can have 1 non-preemptible e2-micro VM instance (1GB 2vCPU, 30GB Disk, etc.) per month free forever in some regions with some restrictions. I wanted the following stuff in my VM before I can install Clickhouse on to that: Ubuntu 20.x LTS SSH access from my machine Enabling SSH-based access to Google Compute Engine VM Step 1 Created an ssh private and public key on my mac using the following command ssh-keygen -t rsa -f ~/.ssh/gcloud-ssh-key -C mrityunjay -b 2048 Step 2 Copied the public key from the console using the following command: cat ~/.ssh/gcloud-ssh-key.pub output ssh-rsa <Gibrish :)> mrityunjay Step 3 I went to Google Cloud Console > Co...