首页 > 解决方案 > 在本机反应中根据某些条件启用道具?

问题描述

我想为原生基本按钮应用带有边框的道具,如果menuIndex == menus.house.

<Button bordered>
    <Text uppercase={false}>House</Text>
</Button>

这是我尝试过的,

<Button {menuIndex == menus.house? '' : bordered}>
    <Text uppercase={false} style={styles.menuTextButtonActive}>
        House 
    </Text>
</Button>

标签: reactjsreact-nativenative-base

解决方案


<Button bordered>
    ...
</Button>

可以理解如下

<Button bordered={true}>
  ...
</Button>

因此,您可以执行如下布尔表达式

<Button bordered={menuIndex == menus.house}>
    <Text uppercase={false} style={styles.menuTextButtonActive}>
        House 
    </Text>
</Button> 

推荐阅读