DEV Community

Shamima Akter
Shamima Akter

Posted on

some of the most important topics in React js

What is React JS?

React JS is a javascript library used in web development to build interactive elements on websites and web applications. React Js used exclusively for “client-side” programming ( building things that a user will see on screen in their browser windows) which makes React JS a Front-End library.

What is the difference between Real DOM and Virtual DOM?

Real DOM: Real DOM updates slow. It can directly update HTML. Real DOM creates a new DOM if the element updates. DOM manipulation is very expensive. It is too much memory wastage.
Virtual DOM: A Virtual DOM is a lightweight Javascript object which originally is just a copy of the real DOM. Virtual DOM updates faster. It can’t directly update HTML. Virtual DOM updates the JSX if the element updates. DOM manipulation is very easy. No memory wastage.

What is the purpose of render() in React.

Each React component must have a render () mandatorily. It returns a single React element which is the representation of the native DOM component. If more than one HTML element needs to be rendered, then they must be grouped together inside one enclosing tag such as

, , etc. It must return the same result each time it is invoked.

What is Props?

Props are the shorthand for properties in React. They are read-only components that must be kept pure immutable. They are always passed down from the parent to the child components throughout the application. A child component can never send a prop back to the parent component. This helps in maintaining the unidirectional data flow and is generally used to render the dynamically generated data.

Arrow function in React

Arrow functions are more of a brief syntax for writing the function expression. They are also called ‘fat arrow’ ( => ) the functions. These functions allow to bind the context of the components property since in ES6 auto binging is not available by default.

Components

In React everything is a component. Components are the building blocks of a React application’s UI. These components split up the entire UI into small independent are reusable pieces. Then it renders each of these components independent of each other without affecting the rest of the UI.

What is a state in React?

The state is the heart of React components. States are the source of data and must be kept as simple as possible. Basically, states are the objects which determine components rendering and behavior. They are mutable unlike the props and create dynamic and interactive components. They are accessed via this. state ().

Explain the lifecycle methods of React components in details –-

Every component in React has lifecycle methods that we can tap into, to trigger changes at a particular phase of the cycle. Each component in react goes through three-phase: Mounting, Updating, and unmounting.
Some of the most important lifecycle methods are:

  1. componentWillMount() – Executed just before rendering takes place both on the client as well as server-side.
  2. componentDidMount() - Executed on the client-side only after the first render. 3.componentWillReceiveProps() - Invoked as soon as the props are received from the parent class and before another render is called.
  3. shouldComponentUpdate () - Returns true or false value based on certain conditions. If I want my component to update, return true else return false. By default, it returns false.
  4. componentWillUpdate() - called just before rendering takes place in the DOM.
  5. componentDidUpdate() - Called immediately after rendering takes place. 7.componentWillUnmount ()- called after the component is unmounted from the DOM. It is used to clear up the memory spaces.

React Hooks

React Hooks cannot be used in class components. They let us write components without class. Functional components were called stateless components. Only class components were used for state management and lifecycle methods. The need to change a functional component to a component, whenever state management or lifecycle methods were to be used, led to the development of Hooks.

What is the difference between functional and class components?

Functional components: The components that return React elements as a result are called functional components. They are basically just simple javascript functions.
Class components: Class components, on the other hand, have been around for quite some time. They use plain Java objects for creating pages. With the React create-a-class-factory method, a literal is passed in defining the method of a new component.

Oldest comments (0)