Skip to main content

React JS - Beginners

 

React JS

React is an open-source JavaScript library for building user interfaces or UI components.
It was created at Facebook and open-sourced in March of 2013. It is used on social platforms like Instagram, Facebook, Twitter. And It is used on content delivery platforms like NetFlix, Spotify.


Beyond Web applications, you can create native mobile applications using React Native.

Check your system node and npm version. Node version should be greater than 8.10 and for npm, we need version 5.6.





 

Create a new React-app:

Command to create a new react app: npx create-react-app new-app

 To start the react app: npm start

 

Folder Structure:



package.json – It contains all the project dependencies.

src folder – It contains the files required to build the application

public folder – when we ready to build the app for production all the built files will be placed in the public folder.

 

Create a React element:

Elements are the building blocks of React apps. We can create a new element in the UI by using  React.createElement() and pass this to ReactDOM.render() which renders an element in the page.

 

ReactDOM.render() takes two arguments.

First – the element that we want to create

Second – where we want to render the element.

React.createElement() – takes three arguments

First – the name of the tag that we want to create,

Second – the properties of the element,

Third  - the children tag or it could be some text.

    import React from 'react';
    import ReactDOM from 'react-dom';
    import './index.css';


    ReactDOM.render(
     React.createElement('h1', null, "Hello World"),
      document.getElementById('root')
    );

 



In the above code, we are creating the “h1” element and rendering it to the “root” element.

 

Where is the root element?

We can find it in the index.html file in the public folder.


In the React.createElement(), we can apply properties to the element as an object.

 

    ReactDOM.render(
     React.createElement('h1', {style: {color: "red" }}, "Hello World"),
      document.getElementById('root')
    );
 

 

Comments

Popular posts from this blog

Observable, Subject , Behavior Subject using RxJS:

  Create an Observable using RxJS:   Import the Observable                                    import  {  Observable  }  from   'rxjs' ; The Observable execution deliver three types of values: "Next" - sends a value such as a Number, a String, an Object, etc. "Error - sends the Error or exception. "Complete" - does not send a value after the Complete                                             ngOnInit ():  void  {                    this . observable$  =  new   Observable ( subscriber   =>  {             ...

What is RxJS?

  What is RxJS? The full form of RxJS is  Reactive Extension for Javascript . As per the official website of RxJS - RxJS is a library for composing asynchronous and event-based programs by using observable sequences . It provides one core type, the  Observable , satellite types (Observer, Schedulers, Subjects) and operators inspired by   Array#extras  (map, filter, reduce, every, etc) to allow handling asynchronous events as collections To manage the sequence of events RxJS combines the Observer pattern with the  Iterator pattern  and functional programming with collections   Observer Pattern: It is a software design pattern in which an object called Subject maintains a list of its dependents called Observers. It works well for applications that expect real-time updates. It is one to many patterns which are one Subject Many Observers. When the subject is updated it will automatically fire an event and notify the observers of the ...

Angular Architecture

  Angular Architecture: Angular is a platform and framework to build single-page client applications using HTML and TypeScript. It is written in Typescript.    The basic building blocks are NgModules. It provides compilation context to components. An angular app has always a root module to enable bootstrapping.                                                               Architectural diagram src: Angular.io   The main building blocks of Angular applications:              Modules              Component             Metadata              Templates              Directives     ...