[英]I want to return 2 button in conditional react native
I'm using react native 0.59.9 and i want to return 2 button in 1 conditional. 我正在使用本机0.59.9反应,我想在1个条件中返回2个按钮。 but it didn't work.
但这没用。 if just one button, it works fine but if i put 2 button i got some error
如果只是一个按钮,它工作正常,但是如果我放2个按钮,我会遇到一些错误
i tried put () in conditional but it didnt work 我试着把()放在条件中,但是没有用
{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/>
}
i want the conditional return that 2 button 我想要条件返回那个2按钮
Wrap both button in the same container or React.fragment. 将两个按钮都包装在同一容器或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/>
} }
In React, you need to have a single parent element that is rendered. 在React中,您需要具有一个呈现的单个父元素。 Try wrapping your buttons with
React.Fragment
. 尝试使用
React.Fragment
包装按钮。 Like this: 像这样:
<>
<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}
/>
</>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.