Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react catch error in component

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }

  componentDidCatch(error, info) {    // Display fallback UI    this.setState({ hasError: true });    // You can also log the error to an error reporting service    logErrorToMyService(error, info);  }
  render() {
    if (this.state.hasError) {      // You can render any custom fallback UI      return <h1>Something went wrong.</h1>;    }    return this.props.children;
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: function 
Javascript :: slice in js 
Javascript :: javascript filter array 
Javascript :: object object js 
Javascript :: average javascript 
Javascript :: round to nearest step 
Javascript :: Find Largest Number by function by javascript 
Javascript :: javascript validator 
Javascript :: else if in javascript 
Javascript :: could not find react-redux context value; please ensure the component is wrapped in a <Provider 
Javascript :: angular flex layout 
Javascript :: react native image border radius not working 
Javascript :: angular loop through array 
Javascript :: react admin data provider 
Javascript :: Sets can be used to store __________. in js 
Javascript :: setstate not updating state immediately 
Javascript :: python json loads single quotes 
Javascript :: how to write last element of array 
Javascript :: regular expression escape character 
Javascript :: request module nodejs 
Javascript :: objects in javascript 
Javascript :: JavaScript finally() method 
Javascript :: axios async await 
Javascript :: angular mat side nav 
Javascript :: Expected an assignment or function call and instead saw an expression 
Javascript :: Activez la compression de texte react js 
Javascript :: signup Using codegniter in ajax 
Javascript :: functions like once 
Javascript :: react state deconstructed 
Javascript :: platform check in react native for status bar color 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =