Skip to content

Instantly share code, notes, and snippets.

@Mayankgupta688
Last active October 22, 2020 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mayankgupta688/ed4e7865be5fd26dd7f68296c22e8d57 to your computer and use it in GitHub Desktop.
Save Mayankgupta688/ed4e7865be5fd26dd7f68296c22e8d57 to your computer and use it in GitHub Desktop.
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