Nishar sheik
Nishar sheik

Reputation: 159

How to navigate from one menu option to other screen

I am using 'react-native-popup-menu'

<MenuOptions customStyles={{ optionText: styles.text }}>
   <MenuOption value="History" text='History' 
                   onPress={()=>{this.props.navigation.navigate('History')}} />
    <MenuOption value="Logout" text='Logout'  onPress={()=>{this.props.navigation.navigate('Login')}}/>
 </MenuOptions>

I want to navigate when I click on any of the menu options to another screen, how can I achieve it?

Upvotes: 1

Views: 560

Answers (1)

Umair Ahmed
Umair Ahmed

Reputation: 577

Looking at the docs from the Library, MenuOption takes an onSelect prop rather than onPress

From their example:

<MenuOptions>
        <MenuOption **onSelect**={() => alert(`Save`)} text='Save' />
        <MenuOption **onSelect**={() => alert(`Delete`)} >
          <Text style={{color: 'red'}}>Delete</Text>
        </MenuOption>
        <MenuOption onSelect={() => alert(`Not called`)} disabled={true} text='Disabled' />
      </MenuOptions>

Changing your onPress to onSelect should start working as per your requirements.

Upvotes: 2

Related Questions