Learn ReactJs

To Know more about ReactJs with the Restful API

Angular JS - Best Framwork

Learn New ideas and techique about the framework.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

React

React
Fundamental of React Js

Saturday, November 4, 2017

ReactJS - Component Life Cycle

Lifecycle Methods

  • componentWillMount is executed before rendering, on both the server and the client side.
  • componentDidMount is executed after the first render only on the client side. This is where AJAX requests and DOM or state updates should occur. This method is also used for integration with other JavaScript frameworks and any functions with delayed execution such as setTimeout or setInterval. We are using it to update the state so we can trigger the other lifecycle methods.
  • componentWillReceiveProps is invoked as soon as the props are updated before another render is called. We triggered it from setNewNumber when we updated the state.
  • shouldComponentUpdate should return true or false value. This will determine if the component will be updated or not. This is set to true by default. If you are sure that the component doesn't need to render after state or props are updated, you can return false value.
  • componentWillUpdate is called just before rendering.
  • componentDidUpdate is called just after rendering.
  • componentWillUnmount is called after the component is unmounted from the dom. We are unmounting our component in main.js.
  • For Example,we will set the initial state in the constructor function. The setNewnumber is used to update the state. All the lifecycle methods are inside the Content component.

  • App.jsx

    import React from 'react';
    
    class App extends React.Component {
    
       constructor(props) {
          super(props);
      
          this.state = {
             data: 0
          }
    
          this.setNewNumber = this.setNewNumber.bind(this)
       };
    
       setNewNumber() {
          this.setState({data: this.state.data + 1})
       }
    
       render() {
          return (
             <div>
                <button onClick = {this.setNewNumber}>INCREMENT</button>
                <Content myNumber = {this.state.data}></Content>
             </div>
          );
       }
    }
    
    class Content extends React.Component {
    
       componentWillMount() {
          console.log('Component WILL MOUNT!')
       }
    
       componentDidMount() {
          console.log('Component DID MOUNT!')
       }
    
       componentWillReceiveProps(newProps) {    
          console.log('Component WILL RECIEVE PROPS!')
       }
    
       shouldComponentUpdate(newProps, newState) {
          return true;
       }
    
       componentWillUpdate(nextProps, nextState) {
          console.log('Component WILL UPDATE!');
       }
    
       componentDidUpdate(prevProps, prevState) {
          console.log('Component DID UPDATE!')
       }
    
       componentWillUnmount() {
          console.log('Component WILL UNMOUNT!')
       }
     
       render() {
          return (
             <div>
                <h3>{this.props.myNumber}</h3>
             </div>
          );
       }
    }
    
    export default App;

    main.js

    import React from 'react';
    import ReactDOM from 'react-dom';
    import App from './App.jsx';
    
    ReactDOM.render(<App/>, document.getElementById('app'));
    
    setTimeout(() => {
       ReactDOM.unmountComponentAtNode(document.getElementById('app'));}, 10000);
    After the initial render, we will get the following screen.
    React Component Lifecycle Initial Screen
  • Only componentWillMount and componentDidMount will be logged in the console, since we didn't update anything yet.
    React Component Lifecycle Initial Log
    When we click the INCREMENT button, the update will occur and other lifecycle methods will be triggered.
    React Component Lifecycle Change Log
    After ten seconds, the component will unmount and the last event will be logged in the console.
    React Component Lifecycle Unmount Log



Friday, November 3, 2017

ReactJs



React is a front-end library developed by Facebook. It is used for handling the view layer for web and mobile apps. ReactJS allows us to create reusable UI components. It is currently one of the most popular JavaScript libraries and has a strong foundation and large community behind it.
ReactJS is JavaScript library used for building reusable UI components. According to React official documentation,
eact is a library for building composable user interfaces. It encourages the creation of reusable UI components, which present data that changes over time. Lots of people use React as the V in MVC. React abstracts away the DOM from you, offering a simpler programming model and better performance. React can also render on the server using Node, and it can power native apps using React Native. React implements one-way reactive data flow, which reduces the boilerplate and is easier to reason about than traditional data binding.

React Features

  • JSX − JSX is JavaScript syntax extension. It isn’t necessary to use JSX in React development, but it is recommended.
  • Components − React is all about components. You need to think of everything as a component. This will help you maintain the code when working on larger scale projects.
  • Unidirectional data flow and Flux − React implements one-way data flow which makes it easy to reason about your app. Flux is a pattern that helps keeping your data unidirectional.
  • License − React is licensed under the Facebook Inc. Documentation is licensed under CC BY 4.0.

React Advantages

  • Uses virtual DOM which is a JavaScript object. This will improve apps performance, since JavaScript virtual DOM is faster than the regular DOM.
  • Can be used on client and server side as well as with other frameworks.
  • Component and data patterns improve readability, which helps to maintain larger apps.

React Limitations

  • Covers only the view layer of the app, hence you still need to choose other technologies to get a complete tooling set for development.
  • Uses inline templating and JSX, which might seem awkward to some developers.
Sr. No.Software & Description
1NodeJS and NPM
NodeJS is the platform needed for the Cordova development. Checkout our NodeJS Environment Setup.

Step 1 – Install Global Packages

We will need to install several packages for this setup. We will need some of the babel plugins, so let’s first install babel by running the following code in the command prompt window.
C:\Users\username>npm install -g babel
C:\Users\username>npm install -g babel-cli

Step 2 – Create the Root Folder

The root folder will be named reactApp and we will place it on Desktop. After the folder is created, we need to open it and create empty package.json file inside by running npm init from the command prompt and follow the instructions.
C:\Users\username\Desktop>mkdir reactApp
C:\Users\username\Desktop\reactApp>npm init

Step 3 – Add Dependencies and Plugins

We will use webpack bundler in these tutorial. Let’s install webpack and webpack-dev-server.
C:\Users\username>npm install webpack --save
C:\Users\username>npm install webpack-dev-server --save
Since we want to use React, we need to install it first. The –save command will add these packages to package.json file.
C:\Users\username\Desktop\reactApp>npm install react --save
C:\Users\username\Desktop\reactApp>npm install react-dom --save
As already mentioned, we will need some babel plugins, so let’s install it too.
C:\Users\username\Desktop\reactApp>npm install babel-core
C:\Users\username\Desktop\reactApp>npm install babel-loader
C:\Users\username\Desktop\reactApp>npm install babel-preset-react
C:\Users\username\Desktop\reactApp>npm install babel-preset-es2015

Step 4 – Create the Files

Let’s create several files that we need. It can be added manually or using the command prompt.
C:\Users\username\Desktop\reactApp>touch index.html
C:\Users\username\Desktop\reactApp>touch App.jsx
C:\Users\username\Desktop\reactApp>touch main.js
C:\Users\username\Desktop\reactApp>touch webpack.config.js

Step 5 – Set Compiler, Server and Loaders

Open webpack-config.js file and add the following code. We are setting webpack entry point to be main.js. Output path is the place where bundled app will be served. We are also setting the development server to 8080 port. You can choose any port you want.
And lastly, we are setting babel loaders to search for js files, and use es2015and react presets that we installed before.

webpack.config.js

var config = {
   entry: './main.js',
 
   output: {
      path:'/',
      filename: 'index.js',
   },
 
   devServer: {
      inline: true,
      port: 8080
   },
 
   module: {
      loaders: [
         {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
    
            query: {
               presets: ['es2015', 'react']
            }
         }
      ]
   }
}

module.exports = config;
Open the package.json and delete “test” “echo \”Error: no test specified\” && exit 1″ inside “scripts” object. We are deleting this line since we will not do any testing in this tutorial. Let’s add the start command instead.
"start": "webpack-dev-server --hot"
Now, we can use npm start command to start the server. –hot command will add live reload after something is changed inside our files so we don’t need to refresh the browser every time we change our code.

Step 6 – index.html

This is just regular HTML. We are setting div id = “app” as a root element for our app and adding index.js script, which is our bundled app file.
<!DOCTYPE html>
<html lang = "en">

   <head>
      <meta charset = "UTF-8">
      <title>React App</title>
   </head>

   <body>
      
id = "app">
src = "index.js"> </body> </html>

Step 7 – App.jsx and main.js

This is the first React component. We will explain React components in depth in a subsequent chapter. This component will render Hello World!!!.

App.jsx

import React from 'react';

class App extends React.Component {
   render() {
      return (
         <div>
            Hello World!!!
         </div>
      );
   }
}

export default App;
We need to import this component and render it to our root App element, so we can see it in the browser.

main.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.jsx';

ReactDOM.render(<App />, document.getElementById('app'));
Note − Whenever you want to use something, you need to import it first. If you want to make the component usable in other parts of the app, you need to export it after creation and import it in the file where you want to use it.

Step 8 – Running the Server

The setup is complete and we can start the server by running the following command.
C:\Users\username\Desktop\reactApp>npm start
It will show the port we need to open in the browser. In our case, it is http://localhost:8080/. After we open it, we will see the following output.
React Hello World

Sunday, October 22, 2017

ReactJS vs AngularJS

Compar :  ReactJS vs AngularJS

Choosing the right framework for a new JavaScript system, application or website is a top priority for any business. It can have a direct bearing on project’s durability and ability to fit in deadlines, further code maintainability, and scalability of your future app.

JavaScript power contest: bare figures

The amount of JavaScript tools is steadily increasing, turning the selection of appropriate technology into a challenge. While among the top discussions is angularjs vs reactjs. Both are highly-performing, advanced and widely used worldwide. According to recent js framework comparison React is regularly used by 53%, while 32% plan to learn it. Angular is applied by 30% and 10% are going to try it. The latest update, Angular 2, is already employed by 13% and 43% want to become familiar it. In the meanwhile, Hot Frameworksranking names AngularJS the 2nd most popular framework globally, taking a back seat to ASP.NET.

International interest:

www

Reactjs vs Angularjs is like blurb against a book

ww11.png

React vs Angular comparison: library against framework

Angular is one of the most popular javascript frameworks and like other similar software suits it offers multiple out-of-the-box solutions and designs. At a time when, React ecosystem comprises any number of composable, targeted online tools and ReactJS acts as one of the building blocks.

Advantages of angularjs

  • Global community support is one of the factors, that can easily make Angular the best javascript framework. Developers and designers constantly collaborate and contribute to the community, increasing credibility and reliability of the framework.
  • It is a full-fledged framework that can run in any browser or platform. Moreover, it is consistent, overwhelmed with ready-made tools, ng components are robust and quite mature, as contrasted with React.
  • Two-way data bind is probably the top feature, as it diffuses the impact after every minor data change and does way with the need for further effort with data sync in view and model.
Given the fact that our company makes active use of ng2, it is essential to include react vs angular 2 comparison as well.
  • TypeScript is an enhanced JS super-set that supplies optional static type checking, object-based programming patterns, and high-performance typing features.
Owing to component-based architecture components have deep binding and each of them comprises elements with only relevant functionality. What is more, they are loosely coupled and properly encapsulated. Such approach makes components easily reusable, enhance their testability and further maintainability.

Advantages of reactjs

  • JSX is a JS syntax that enables HTML quotes and usage of HTML tag syntax for subcomponents rendering. It promotes building of machine-readable code and provides ability to compound components in one compile-time verified file.
  • Prompt rendering is among the best features of React that gives a significant edge over Angular. The technology comprises smart methods to mitigate the amount of DOM operations, optimize and accelerate the updates process. Virtual DOM (Document Object Model) is of great use while handling vast databases.
  • The core difference between reactjs and angularjs is that React is JS-centric, while ng2 remains HTML-centric. JavaScript is far more robust, than HTML, that makes React far more simple, focused and consistent.
  • Disadvantages of angularjs

    Disadvantages of react.js

  • Comparing react vs angular performance, first of all it’s worth mentioning that reactJS is not a full-scale framework and for this very reason integration of the UI library into a common MVC framework requires deeper programming knowledge. It is still young and not mature, considering tutorial volumes, limited ecosystem, etc.
  • Apart from pros and cons of reactjs, we should also mention Flux that is frequently applied for adding a structure and architecture to react app. Usage of both technologies can become a challenge for non-experienced programmer, as it lacks structured and comprehensive documentation or guide.
  • Despite a comprehensive and clear manual, steep learning curve and complexity are named among the main weak points of Angular.js. Like any other client-side rendering technology in javascript framework comparison list, programmers should place special emphasis on security to make apps reliable and safe. Though, with introduction of Angular Universal and pre-rendering option in ng2 this issue was defused.

Conclusion

React and Angular offer completely diverse approaches to web application development for startup, small and midmarket businesses. Both technologies are powerful and flexible, while none of them is worse or better, than the other. Depending upon custom app goals and particular system constraints, developers can run from ng2 to React, and back.
Opting for Angular, it usually assumes the creation of core skeleton for a front-end app, whereas React.js can be applied to improve its specific parts. Moreover, it can be integrated with other frameworks, like Backbone or even well-known Angular.