Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ErrorBoundary key={index}>
- <Car name={car.name} />
- </ErrorBoundary>
- // ----
- import React, { Component } from 'react'
- export default class ErrorBoundary extends Component {
- state = { hasError: false }
- // данный метод будет вызван если его дети выхватят ошиюку
- // т е это обертка !
- componentDidCatch(error, info) {
- this.setState({hasError: true})
- }
- render() {
- if (this.state.hasError) {
- return <h1 style={{color: 'red'}}> Something went wrong </h1>
- }
- return this.props.children
- }
- }
Add Comment
Please, Sign In to add comment