React Native: Call Redux getState() inside Component
<p>What I'm trying to achieve is this: I want to check whether the NavigationDrawer is open and if yes, then when the user clicks back (on Android) I want to close the drawer instead of quitting the app. I have a boolean (isDrawerOpen) in the Redux stored which is updated properly. </p>

<p>My problem is that I can't figure out how to call <code>getState()</code> inside my component. The component looks something like this:</p>

<pre><code>class MainScreen extends Component {
  constructor(props) {
    super(props)

    BackAndroid.addEventListener('hardwareBackPress', function () {
      if (somehow.getState().isDrawerOpen) {
        // Close drawer.
        return true;
      } 

      return false;
    });
  }

  render() {
      return ...
  }
}

const mapStateToProps = (state) =&gt; {
  return {
    ...
  }
}

export default connect(mapStateToProps)(MainScreen)
</code></pre>

<p>And the store is created in another container component, like this:</p>

<pre><code>export default class App extends Component {
    render() {
        return (
            &lt;Provider store={store}&gt;
                 &lt;MainScreen /&gt;
            &lt;/Provider&gt;
        );
    }
}
</code></pre>

<p>In my <code>MainScreen</code> component whenever I need to dispatch an action, I do it by calling <code>this.props.dispatch(someAction())</code>. However, <code>this.props.getState()</code> doesn't seem to exist.</p>

<p>One solution of course would be to update my MainScreen's state whenever the mapStateToProps() is triggered and then instead of checking Redux's state, check the component's state. However, updating my component's state would cause the render() to be triggered and that's not what I want. Besides, I would like to anyhow know for future reference how to access Redux's state from inside a component.</p>

<p>Thanks in advance!</p>