Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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