Shyam Hande has Published 72 Articles

Returning adjacent element in React.js and HOC

Shyam Hande

Shyam Hande

Updated on 04-Sep-2019 13:16:01

213 Views

Generally the return statement in React’s render method returns a single div element enclosing all the child jsx like below −render(){    return (                Header          Test          ); }Here we cannot simply return multiple ... Read More

React.js routing

Shyam Hande

Shyam Hande

Updated on 04-Sep-2019 13:00:52

2K+ Views

Before React Router v4, the routing in react was static but after v4 update its dynamic. In single page applications, we have only one page index.html and different components which gets displayed based on routes.In non spa web applications, server returns a page on request. To start with routing , ... Read More

React.js component lifecycle error handling phase

Shyam Hande

Shyam Hande

Updated on 04-Sep-2019 12:56:01

622 Views

There are two main methods in error handling. These method are used in the error boundary mechanism in React. We wrap the component ( from where there is a possibility of error occurrences ) in a class which handles the below methods.Static method getDerivedStateFromError(error)componentDidCatch(error, info)Static getDerivedStateFromError(error): As name of the ... Read More

React.js Component Lifecycle - Updating phase

Shyam Hande

Shyam Hande

Updated on 04-Sep-2019 12:03:46

228 Views

The update lifecycle can be triggered by two events −Update of props by parent componentChange in local stateUpdate of props by parent componentcomponentWillReceiveProps(nextProps) −This is the first method which gets called on prop change. It contains one argument nextProps means the newly changed props.Here, we can synchronize local state with ... Read More

React.js Component Lifecycle - Unmounting

Shyam Hande

Shyam Hande

Updated on 04-Sep-2019 11:52:05

283 Views

ComponentWillUnmount is the only method that executes in unmount phase.Component enters into this phase when there is no matching in element tree for this component.Just before the component gets removed from actual DOM, this method gets called.Along with removal of this component from DOM tree, all children of this component ... Read More

React.js Component Lifecycle - Mounting phase

Shyam Hande

Shyam Hande

Updated on 04-Sep-2019 11:43:13

239 Views

Each stateful means class based component goes through four types of lifecycle phases.Mounting or CreationUpdatingUnmounting or DestroyError handling phaseReact.js Component Lifecycle - Mounting phaseThe methods that executes during creation lifecycle are −constructorcomponentWillMount (Only available till version 17 )rendercomponentDidMountconstructor ()It’s an ES6 feature and not a React provided method.React uses the ... Read More

Pure Component in React.js

Shyam Hande

Shyam Hande

Updated on 04-Sep-2019 11:35:15

2K+ Views

We have a lifecycle method called shouldComponentUpdate which by default returns true (Boolean) value.The purpose of the shouldComponentUpdate is we can custom implement the default behavior and decide when react should update or re-render the component.Generally we use state or props value to decide the update cycle. React has now ... Read More

Nested Routing in React.js

Shyam Hande

Shyam Hande

Updated on 04-Sep-2019 11:30:19

331 Views

We have an app.jsx componentimport React, { Component } from 'react'; import { Link, Route, Switch } from 'react-router-dom'; import Category from './Category'; class App extends Component {    render() {       return (                           ... Read More

Navigation in React.js Routing

Shyam Hande

Shyam Hande

Updated on 04-Sep-2019 11:20:20

6K+ Views

We have an index.js file as −import React from 'react' import ReactDOM from 'react-dom' import './index.css' import { Route, Link, BrowserRouter } from 'react-router-dom' import App from './App' import AboutUs from './ AboutUs’; import ContactUs from './ContactUs'; const routs = (    < BrowserRouter >         ... Read More

React.js memo function in functional component

Shyam Hande

Shyam Hande

Updated on 04-Sep-2019 11:07:57

284 Views

We have shouldComponentUpdate in class based component as lifecycle method. This method can be used to achieve the performance optimization by comparing props (previous and next) and executing render conditionally .We have React.PureComponent as well which can do shallow comparison of state and props. But in functional component we don’t ... Read More

Advertisements