Last active
October 22, 2020 05:14
-
-
Save Mayankgupta688/ed4e7865be5fd26dd7f68296c22e8d57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export default class App extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
hasError: false | |
} | |
} | |
componentDidCatch(error, info) { | |
console.log("Component Did Catch Error"); | |
} | |
static getDerivedStateFromError(error) { | |
return { hasError: true }; | |
} | |
render() { | |
return ( | |
<div> | |
{ !this.state.hasError && <EmployeeDetails /> } | |
{ this.state.hasError && <ErrorComponent /> } | |
</div> | |
) | |
} | |
} | |
function ErrorComponent() { | |
return <h2>Do not enter empty spaces in the User Name Input Box</h2> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment