React Native Navigation: Check if drawer is opened or not

You can check if drawer is open by getting the navigation state:

const state = navigationRef.current.getRootState();
const isDrawerOpen = state.history.some((it) => it.type === 'drawer');

The above code assumes that drawer is at root. If it’s nested, you’ll need to traverse the state to find the state object with type: 'drawer'.

It’s not clear why you need to check it from the question. Normally you shouldn’t need to check it. If you dispatch DrawerActions.openDrawer() if drawer is already open, nothing will happen. So the check is unnecessary. If you want to close the drawer if it was open, you can dispatch DrawerActions.toggleDrawer() instead.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top