Answer the question
In order to leave comments, you need to log in
Why doesn't componentDidCatch work?
Made the ErrorBoundary component wrap the application
import React, { Component } from 'react'
class ErrorBoundary extends Component {
state = {
hasError: false
}
componentDidCatch(error, info) {
console.log(error)
console.log(info)
this.setState({
hasError: true
})
}
render () {
if(this.state.hasError) {
return <h1>Какая-то ошибка</h1>
}
return this.props.children
}
}
export default ErrorBoundary
export const postVolonteerList = async (page = 1, perPage = 10, filters) => {
try {
let res = await instance
.get(
`/api/voluinteers`,
{
params: {
page: page,
page_size: perPage,
...filters
}
});
return res.data
}catch(err){
console.log('ОШИБКА', err.message);
throw err
}
};
Answer the question
In order to leave comments, you need to log in
componentDidCatch is triggered when an error occurs during rendering, or when an error occurs when working with state
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question