Sitemap
Fadhilahamed

Fadhilahamed

software engineering undergraduate (IT20784720)

React Js

4 min readMay 15, 2022
Press enter or click to view image in full size

What is React js?

React js is an open-source JavaScript library that is used to build user interfaces for single-page applications. It encourages the development of reusable user interface components, which can be used to present data that changes over time. And also React js serves views of MVC architecture.

Why React?

React uses a component-based approach and the use of simple JavaScript makes react very simple to understand. React uses a special syntax called JSX which allows to mixing of HTML with JavaScript. But developers can use plain JavaScript but JSX is much easier to use.

React also can be rendered on the server using Node.

React uses one-way data binding and uses flux to control the flow of data to components through one control point.

React js applications are easy to test and React js doesn’t offer any build-in containers for dependency.

The app's performance can be improved using a virtual Dom which is a JavaScript object.

What is babel?

Babel is a JavaScript compiler that can translate programming language to JavaScript. React uses babel to convert JSX into JavaScript.

The babel can be imported using and script tag as follows,

<script type = “text/babel” >

What is Parcel?

The parcel is a web application bundler that was differentiated by its developer experience. It requires zero configuration and it offers blazing fast performance.

Parcel works great for building single or multi—page React js applications. And allows creating a relatively lean setup of React js.

Parcel supports JSX, Typescript, SCSS, SVG, and many styling methodologies out of the box.

What is a Web pack?

A web pack is a bundler that uses a dependency graph to bundle the code and assets (such as images) which can then be deployed.

Web pack simplifies the use of JavaScript project modules. Support for build system as well as module bundling. Most browsers natively support modules, so using a web pack to compile them gives some extra benefits.

One benefit to using a web pack is its support for loaders. Loaders allow web packs to handle types beyond JavaScript and JSON and CSS transformation.

Another benefit is to using a web pack is the ability to minify the code of the project.

Creating a React App

We can create react app using a single command,

npx create — react — app folder name

Create — react — app is a CLI tool for setting up or bootstrapping a boilerplate development setup to make react applications.it takes much storage due to the heavy the dependencies and plugins it automatically installed as node modules.

And also we can create react application without using create — react — app CLI. So for that, we can use a parcel or web pack to create a react app from the ground.

In this blog, I will show how to create a react application using Parcel.

1. First create package. Json file by giving the following command in the terminal,

Get Fadhilahamed’s stories in your inbox

Join Medium for free to get updates from this writer.

npm init –y

By giving –y it defaults fills all the entries in package. Json file.

Press enter or click to view image in full size

2. Install Parcel related dependency

npm i –D parcel@next

3. Install React related dependencies,

npm i react react-dom

4. Add the Start Script to package. Json

“scripts”: {

“start”: “parcel index.html”

},

5. Create the index.html file, and add <div> tag with id inside the body and <Script> tag,

<div id=” root” > was created because all react page applications are displayed here.

The script tag is used to inject the index.js.

Press enter or click to view image in full size

6. Create index.js with the following code,

React version used 17.0.2.

Render app.js and the id of <div> tag in index.html.

Press enter or click to view image in full size

7. Create a file to display data to the index.html, in this example I created a file app.js.

Press enter or click to view image in full size

8. Start the Application,

npm start

Press enter or click to view image in full size

9. Run the application in the browser.

Press enter or click to view image in full size

so the browser will display the content in app.js file.

conclusion

it is easy to use create -react -app and create the react app, but when creating the react applications from the ground by using parcel it takes less storage.

also, parcel supports most of the common web development extensions.

--

--

Fadhilahamed
Fadhilahamed

Written by Fadhilahamed

software engineering undergraduate (IT20784720)