TypeError: undefined is not an object (evaluating 'this')

I do not get an error when I delete the component menu I created specially from where I put it, but I get an error when my component is there. Thank you for your comments already.



import Menu from './Navigator'
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
import { faBars } from '@fortawesome/free-solid-svg-icons';

export default class HeaderLeft extends Component {
    constructor(props){
        super(props);
        this.state={check:false}
    }
    render() {
        return (<SafeAreaView><View onStartShouldSetResponderCapture={() => { this.setState({ check: !this.state.check }) }} style={styles.align}>
            <FontAwesomeIcon icon={faBars} size={16} color={"#2D6A4F"} /><Menu check={this.state.check}></Menu></View></SafeAreaView>)
    }

}
const styles = StyleSheet.create({

    align: {
        height: 60, display: 'flex', justifyContent: 'center', padding: 20
    },

});```

1 thought on “TypeError: undefined is not an object (evaluating 'this')”

  1. Have a try by making the changes as the below code in your code.:

    add below in the constructor:

    this.handleResponderCapture = this.handleResponderCapture.bind(this)
    

    Add below method:

    handleResponderCapture = () => {
        this.setState({
            check: !this.state.check
        })
    }
    

    Make changes as below in View

    <View
        onStartShouldSetResponderCapture={this.handleResponderCapture}
        style={styles.align}
    >
    
    Reply

Leave a Comment