reactjs - 我想在有条件的本机反应中返回 2 个按钮
问题描述
我正在使用 react native 0.59.9,我想在 1 个条件下返回 2 个按钮。但它没有用。如果只有一个按钮,它工作正常,但如果我放 2 个按钮,我得到了一些错误
我试过把()有条件的,但它没有用
{this.props.options.config.editable ?
<Button
onPress={ () => this.bottomSheet.open()
}
color={buttonTextColor}
title={locals.config.title}
/>
//this button make the error
<Button
onPress={() => this.bottomSheet.open()
}
color={buttonTextColor}
title={locals.config.title}
/>
:
<View/>
}
我想要有条件的返回那个 2 按钮
解决方案
将两个按钮包装在同一个容器或 React.fragment 中。
{ this.props.options.config.editable ?
<React.Fragment>
<Button
onPress={
Platform.OS === 'ios'
? this._onPressImage
: () => this.bottomSheet.open()
}
color={buttonTextColor}
title={locals.config.title}
/>
//this button make the error
<Button
onPress={
Platform.OS === 'ios'
? this._onPressImage
: () => this.bottomSheet.open()
}
color={buttonTextColor}
title={locals.config.title}
/>
</React.Fragment>
:
<View/>
}
推荐阅读
- php - WordPress 迁移发布问题
- office365api - 未收到 Microsoft O365 管理 API 的任何 webhook 通知
- flutter - TimeServiceProvider 不能分配给列表类型 SingleChildWidget
- c# - C# 戈多 | 错误:call_build:EditorPlugin 构建回调失败
- reactjs - 未找到生产抛出文件中的哈希路由错误
- windows - 为什么 dotnet publish 命令在 Windows git bash 终端上有效,但在 Dockerfile 中无效?
- regex - 从字符串中删除特定字符以整理 URL
- java - 如何使我的依赖项对其他开发人员可用?
- sqlite - Discord.js 使用 better-sqlite3 向 XP 系统添加排名功能
- c - C - 如何检查指针是否已从另一个指针中释放?