简体   繁体   中英

React Native Paper Radio Button onPress event not working

For some reason my onPress event is not working with 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';

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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