Skip to main content
Version: 6.6

<NetworkErrorBoundary />

Displays a fallback component when a network error happens in its subtree.

Catches any error with status member.

interface Props {
children: React.ReactNode;
fallbackComponent: React.ComponentType<{
error: NetworkError;
export default class NetworkErrorBoundary extends React.Component<Props> {
static defaultProps: {
fallbackComponent: ({ error }: { error: NetworkError }) => JSX.Element;

Custom fallback usage example:

import React from 'react';
import { CacheProvider, NetworkErrorBoundary, NetworkError } from 'rest-hooks';

function ErrorPage({ error }: { error: NetworkError }) {
return (
{error.status} {error.response && error.response.statusText}

export default function App(): React.ReactElement {
return (
<NetworkErrorBoundary fallbackComponent={ErrorPage}>
<Router />

Note: Once <NetworkErrorBoundary /> catches an error it will only render the fallback until it is remounted. To get around this you'll likely want to place the boundary at locations that will cause remounts when the error should be cleared. This is usually below the route itself.