const GuardedRoute = ({ component: Component, auth, ...rest }) => (
<Route {...rest} render={(props) => (
auth === true
? <Component {...props} />
: <Redirect to='/' />
)} />
)
export default GuardedRoute;
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
// static getDerivedStateFromError(error) {
// return { hasError: true };
// }
componentDidCatch(error, errorInfo) {
console.log('caught an error', error, errorInfo);
this.setState({ error: true})
}
render() {
if (this.state.error) {
return (
<div>
An error has occurred!
</div>
);
}
return this.props.children;
}
}
export default ErrorBoundary;