Posts

Showing posts from February, 2022

How can you force react components to rerender without calling the set state?

Image
React components re-render on their own whenever there are some changes in their props or state. Simply updating the state, from a random place in the code, causes the User Interface (UI) elements that get re-rendered automatically. In class components, you have the option to call force update to force a rerender. In function components, however, there’s no chance of force update as there is no equivalent, but you have the option to contrive a way to force updates with the help of the useState hook. Force update must be tried and avoided as it deviates from a React mindset. The React docs cite some examples of when force updates can be used.  By default, when there is a change in a component’s state or props, the component will re-render. However, if there are implicit changes like changes in deep data within an object that too without the object itself changing or if your method to render depends on another data, you have the option to tell React that it requires to re-run render ...

How to create a Button in React app?

  Buttons allow users to take action, and make choices, with a single tap. It communicates actions that users can take. So, in this article, we will see  how to create a Button in React app. They are typically placed throughout your UI, in places like Dialogs, Modal windows, Forms, Cards, and Toolbars. Creating a Button in react native is very simple. First, we have to import the button component from React Native. import React, { Component } from 'react' import { Button } from 'react-native' const Test = () => { return( <Button // Define Button property /> ) } export default Test The above syntax shows how a button is used in react native. It involves defining an XML tag with a button element. Also, according to our requirements, different properties can be defined for a button. There are five types of Buttons which are listed below: 1) Basic Types:  These fall into the basic category and can be of the following types: Button: ...

How to create a Brush Bar Chart using Recharts?

  Rechart JS  is a library that is used for creating charts for React JS. So, in this article, we will see  how to create a Brush Bar Chart using Recharts. This library is used for building Line charts, Bar charts, Pie charts, etc, with the help of React and D3 (Data-Driven Documents).  Brush Bar  charts   are those bar charts that have a large number of data points. So to view and analyze them efficiently there is a slider down them. It helps the viewer to select some data points that the viewer needs to be displayed. We create a normal bar chart using the BarChart and Bar component of recharts npm package. To convert it to the Brush bar chart we add the Brush component to the BarChart component. Creating React Application And Installing Module: 1)  Create a React application using the following command. npx create-react-app foldername 2)  After creating your project folder i.e. folder name, move to it using the following command. cd foldername 3...