Guest User

Untitled

a guest
Oct 15th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. <ErrorBoundary key={index}>
  2. <Car name={car.name} />
  3. </ErrorBoundary>
  4.  
  5.  
  6. // ----
  7.  
  8. import React, { Component } from 'react'
  9.  
  10. export default class ErrorBoundary extends Component {
  11.  
  12. state = { hasError: false }
  13.  
  14. // данный метод будет вызван если его дети выхватят ошиюку
  15. // т е это обертка !
  16. componentDidCatch(error, info) {
  17. this.setState({hasError: true})
  18. }
  19.  
  20. render() {
  21. if (this.state.hasError) {
  22. return <h1 style={{color: 'red'}}> Something went wrong </h1>
  23. }
  24. return this.props.children
  25. }
  26. }
Add Comment
Please, Sign In to add comment