Why componentDidCatch
does not work in my react-native app. componentDidCatch
does not handle errors.
React native v: 50.3 React: 16.0.0
import React, {Component} from 'react'; import {View, Text} from 'react-native'; import Logo from './SignUpInit/Logo'; import SignUp from './SignUpInit/SignUp'; import Social from './SignUpInit/Social'; import styles from './SignUpInit/styles'; export default class SignUpInit extends Component { state = { componentCrashed: false, count: 0, } componentDidCatch(error, info) { console.log(error); console.log(info); console.log('_______DID CATCH____________'); this.setState({componentCrashed: true}); } componentDidMount(){ setInterval(()=>this.setState({count: this.state.count+1}),1000); } render() { if (this.state.componentCrashed) { return ( <View> <Text> Error in component "SingUpInit" </Text> </View> ); } if(this.state.count > 5){ throw new Error('Error error error'); } return ( <View style={styles.main}> <Logo/> <SignUp/> <Social/> </View> ); } }