Front End Technology Articles

Page 647 of 652

ReactJS componentDidCatch method

Rahul Bansal
Rahul Bansal
Updated on 18-Mar-2021 1K+ Views

In this article, we are going to see how to execute a function in the commit phase if some error occurs in the Component.This method is called when a component or any children component encounters some error during the React Component Lifecycle. This method allows us to handle the error boundaries of the application.Unlike the getDerivedStateFromError method, this method is called during the commit phase, so side-effects are also allowed in this method.SyntaxcomponentDidCatch(err, data)Parameterserr - Error thrown by the component.data - Stores information about the component which has thrown the error.ExampleIn this example, we will build a React application that displays the ...

Read More

ReactJS – bind() method

Rahul Bansal
Rahul Bansal
Updated on 18-Mar-2021 5K+ Views

In this article, we are going to see how to pass arguments to a function in a React applicationReact has a predefined bind() method which we can use to pass the arguments to a function in the class based components.Syntaxthis.func.bind(this, [args...])It accepts two parameters, this keyword and the arguments. 'this' keyword is used to pass the reference to that function while the second parameter is passed as arguments to the function.ExampleIn this example, we will build a React application that passes the arguments to a function when a button is clicked.App.jsximport React from 'react'; class App extends React.Component { ...

Read More

ReactJS – Axios Interceptors

Rahul Bansal
Rahul Bansal
Updated on 18-Mar-2021 11K+ Views

In this article, we are going to learn how to intercept every request or response that is being sent by Axios Interceptors in a React application.Axios interceptors are the default configurations that are added automatically to every request or response that a user receives. It is useful to check response status code for every response that is being received.ExampleIn this example, we will build a React application that automatically checks and logs the status code that is sent by the server while sending a POST request from our React application.We have to set all the configuration in the most global ...

Read More

ReactJS – Fragments

Rahul Bansal
Rahul Bansal
Updated on 18-Mar-2021 510 Views

While building a ReactJS application, all the JSX code needed to be wrapped down inside a parent tag.ReactJS Fragments were introduced with React 16.2 version to remove the need to define an extra tag which also takes extra memory.Without FragmentsThe following sample code shows how to create a simple React application without React Fragments.ExampleApp.jsximport React from 'react'; class App extends React.Component {    render() {       return (                       TutorialsPoint             Simply Easy Learning               ...

Read More

ReactJS – Component vs PureComponent

Rahul Bansal
Rahul Bansal
Updated on 18-Mar-2021 1K+ Views

In this article, we are going to see the difference between Component and PureComponent. In ReactJS, Components are widely used to make an App more efficient and effective to use.ReactJS provides two different ways to use components – Component or PureComponent.ComponentIt is the type of component which re-renders itself every time when the props passed to it changes or its parent component re-renders.Our first component in the following example is App. This component is the parent of the Comp1 component. We are creating Comp1 separately and just adding it inside the JSX tree in our App component. Only the App ...

Read More

ReactJS – Cleaning up with useEffect hook

Rahul Bansal
Rahul Bansal
Updated on 18-Mar-2021 801 Views

In this article, we are going to see how to clean up the subscriptions set up in the useEffect hook in the functional component.Once the effects are created, then they are needed to be cleaned up before the component gets removed from the DOM. For this, cleaning up effect is used to remove the previous useEffect hook’s effect before using this hook of the same component again.SyntaxuseEffect(()=>{    return ()=>{} } ,[]);ExampleIn this example, we will build a React application which displays the coordinates of the mouse pointer when it is moved over the screen. For this to implement, we ...

Read More

Import Files and Images in ReactJS

Rahul Bansal
Rahul Bansal
Updated on 18-Mar-2021 5K+ Views

In this article, we are going to see how to import CSS Files, images and functions defined in other folder to the main App.js file.In React, we need to dynamically import the images from their folder.ExampleIn this example, we will define a project structure with the images and components already defined in the assets and components folder and then we are going to dynamically import them in our main App.js file.Project StructureApp.jsimport React from 'react'; import MyComponent from './components/my -component.js'; import TutorialsPoint from './assets/img.png'; const App = () => {    return (           ...

Read More

HTTP Requests with axios in ReactJS

Rahul Bansal
Rahul Bansal
Updated on 18-Mar-2021 951 Views

In this article, we are going to learn how to send and receive Http Responses with axios in a React application.Why Use axios?Automatic conversion of response to JSON formatEasy to use and more secureSetting up global HTTP interceptorsSimultaneous RequestInstalling the modulenpm install axiosORyarn add axiosNpm is the node package manager which manages our React package but yarn is the more secure, faster and lightweight package manager.Sending GET requesthttps://jsonplaceholder.typicode.com/todos/1Jsonplaceholder is a fake API which is used to learn the process of the sending requests.ExampleApp.jsximport React, { useEffect, useState } from 'react'; const App = () => {    const [data, setData] = useState(null);    const ...

Read More

How to use Radium in ReactJS?

Rahul Bansal
Rahul Bansal
Updated on 18-Mar-2021 913 Views

In this article, we are going to see how to apply inline styling to a component in a React application.Radium is a popular third package application used to add inline styling and pseudo selectors such as :hover, :focus, :active, etc. to a JSX element.Installing the modulenpm install --save radiumORyarn add radiumNpm is the node package manager which manages our React package but yarn is the more secure, faster and lightweight package manager.ExampleApp.jsximport Radium from 'radium'; import React from 'react'; function App() {    const style = {       ':hover': {          backgroundColor: '#000',     ...

Read More

How to update parent state in ReactJS?

Rahul Bansal
Rahul Bansal
Updated on 18-Mar-2021 3K+ Views

In this article, we are going to see how to update the parent state from a child component in a React application.To update the parent state from the children component, either we can use additional dependencies like Redux or we can use this simple method of passing the state of the parent to the children and handling it accordingly.ExampleIn this example, we will build a React application which takes the state and the method to update it from the parent component and pass it to the children component and after handling it we will pass the updated state to the ...

Read More
Showing 6461–6470 of 6,519 articles
« Prev 1 645 646 647 648 649 652 Next »
Advertisements