Earid

ErrorBoundries.js

24/01/2021

by Earid

import React, { Component } from 'react'

 class ErrorBoundries extends Component {
constructor(props) {
    super(props)

    this.state = {
         hasError: false
    }
}
     static getDerivedStateFromError(error){
        return {
            hasError:true
        }
     }
    render() {
        if (this.state.hasError){
            return <p>Something went wrong</p>
        }
        return this.props.children
    }
}

export default ErrorBoundries
Facebook
X
LinkedIn
Email
Pinterest
WhatsApp

ErrorBoundries.js