Lyle
Lyle

Reputation: 125

How to add view dynamically with state in ReactNative

I'm using a react-native-popup-menu. Here's the code:

      <Menu>
         <MenuTrigger text='Select action' />
         <MenuOptions>
           <MenuOption onSelect={() => alert(`Save`)} text='Save' />
           <MenuOption onSelect={() => alert(`Not called`)} disabled={true} text='Disabled' />
        </MenuOptions>
      </Menu>

And I wanna dynamically add MenuOption from an array in my state. What should I do for that?

Upvotes: 2

Views: 649

Answers (1)

Mohamed Khalil
Mohamed Khalil

Reputation: 3126

using array.map()

{this.state.menuOptions.map(menuOption => <MenuOption onSelect={() => alert(`Save`)} text='Save' />)}

Upvotes: 3

Related Questions