[React Native]: Can't find variable: DeviceEventEmitter

1k views Asked by At

I'm attempting to use the event listener to direct when to open/close a view (i.e close on navigation), but I can't seem to reference the DeviceEventEmitter variable. It seems to be OK on componentWillMount, but then crashes when the actual navigation will occur (on componentWillUnmount)

I've seen some references to RTCDeviceEventEmitter, and simply EventListener, but I've been unable to find a concrete solution.

import { Text, View, TouchableOpacity, DeviceEventEmitter } from 'react-native';

constructor(props) {
    super(props);

    this.state = {
        currentRequest: "",
        displayRequest: false
    }
}

componentWillMount() {
    DeviceEventEmitter.addListener(
        NavigationService.NavigationEvents.Will,
        this.hideRequestLog
    );
    console.log('mounted');
}

componentWillUnmount() {
    DeviceEventEmitter.removeListener(
        NavigationService.NavigationEvents.Will,
        this.hideRequestLog
    );
    console.log('unmounted');
}

hideRequestLog() {
    this.setState({
        displayRequest: false
    })
}
0

There are 0 answers