简体   繁体   English

React Native Paper Radio Button onPress 事件不起作用

[英]React Native Paper Radio Button onPress event not working

For some reason my onPress event is not working with React Native Paper RadioButton.出于某种原因,我的 onPress 事件不适用于 React Native Paper RadioButton。 I have follow instructions per docs I believe我相信每个文档都按照说明进行操作

not working:不工作:

<RadioButton.Item
                    label={item.templateName}
                    value={item._ref}
                    mode="android"
                    position="leading"
                    labelStyle={{textAlign: 'left'}}
                    onPress={()=> setValue('something')}
                  />

working however if I use set state the page will render to much工作但是如果我使用设置状态页面将呈现很多

<RadioButton.Item
                    label={item.templateName}
                    value={item._ref}
                    mode="android"
                    position="leading"
                    labelStyle={{textAlign: 'left'}}
                    onPress={setValue('something')}
                  />

I hope this might be useful for you.我希望这可能对你有用。 Please keep below code in your file.请在您的文件中保留以下代码。

import this : import { RadioButton } from 'react-native-paper';导入这个: import { RadioButton } from 'react-native-paper';

const [value, setValue] = React.useState('first');

Then keep radio buttons in group tab like below:然后将单选按钮保留在组选项卡中,如下所示:

<RadioButton.Group onValueChange={value => setValue(value)} value={value}>
  <RadioButton.Item label="First item" value="first" />
  <RadioButton.Item label="Second item" value="second" />
</RadioButton.Group>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM