All files / Errors NavigationError.js

100% Statements 6/6
100% Branches 2/2
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38        12x 12x               1x       29x 1x                             28x        
import React, { Component } from 'react';
 
class NavigationError extends Component {
    constructor(props) {
        super(props);
        this.state = {
            hasError: false,
            info: '',
            error: '',
        };
    }
 
    componentDidCatch(error, info) {
        this.setState({ hasError: true, info, error });
    }
 
    render() {
        if (this.state.hasError) {
            return (
                <ul className="px-4 my-auto">
                    <li className="w-full text-center p-2 rounded-lg transition-colors duration-200 focus:outline-none text-gray-600 dark:text-gray-400">
                        Failed to load navigation.
                        </li>
                    <li className="w-full text-center p-2 rounded-lg transition-colors duration-200 focus:outline-none text-gray-600 dark:text-gray-400">
                        {this.state.error.toString()}
                    </li>
                    <li>
                        <button className="w-full text-center p-2 rounded-lg transition-colors duration-200 focus:outline-none text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-100 hover:bg-red-100 dark:hover:bg-red-600"
                            onClick={this.props.retry}>Click here to try again.</button>
                    </li>
                </ul>
            );
        }
        return this.props.children;
    }
}
 
export default NavigationError;