axios.interceptors in hoc withErrorHandler work for clicked method in App.js, but do not work for componentWillMount or componentDidMount in App.js. How can I fix it?
App.js
class App extends Component {
componentDidMount() {
axios.get('https://wrongaddress')
.then(response => {
console.log(response);
});
}
clicked() {
axios.get('https://wrongaddress')
.then(response => {
console.log(response);
});
}
render() {
return (
<button onClick={this.clicked}>btn</button>
);
}
}
export default withErrorHandler(App, axios);
hoc/withErrorHandler.js
const withErrorHandler = ( WrappedComponent, axios ) => {
return class extends Component {
componentDidMount() {
axios.interceptors.request.use(req => {
console.log(req);
return req;
});
}
render() {
return (
<WrappedComponent {...this.props} />
);
}
}
};