简体   繁体   English

我想在条件反应本机中返回2按钮

[英]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.

相关问题 我想要这种带有触发按钮的底页反应原生 - I want this type of bottomsheet with trigger button in react native React Native Navigator renderView返回条件不合逻辑 - React Native Navigator renderView return conditional not logical React Native:在视图中返回条件语句 - React Native : Return conditional Statement in View 反应本机纸:我想在按下反应本机纸的按钮时更改按钮的颜色 - react native paper : i want to change button's color when i press react native paper's button 我有一个 function 我想返回多个 object 第二个任务完成(反应原生) - I have a function that I want to return multiple object the second the task complete (react native) 我想从包含图像 react-native 的链接/网址的数组中返回平面列表中的图像 - I want to return images in flatlist from an array that contians links/urls for images react-native 我想将JSON文件中的数据用作单选按钮的标签(本机反应) - I want to use the data from a JSON file as the label for my radio button (react native) 这个 React Native 组件有什么问题? 我想在按下按钮时更改方块的颜色 - What is wrong with this Component of React native ? I want to change color of square block on button press 我想用原生按钮制作一个圆圈 - I want to make a circle with buttons in react native 在react-native自定义按钮中有条件地呈现组件 - Conditional rendering of components in a react-native custom button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM