[英]How to store chosen radio button value in a AsyncStorage in React Native?
我想在 AsyncStorage 中存储/保存用户选择的单选按钮值。 这是如何实现的? 我正在从另一个文件中检索单选按钮值并将它们分配给标签。 这些是我的单选按钮的结构:
import RadioButtonRN from 'radio-buttons-react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
const Radio = () => {
const label1 = Questions[2].answers[0].answer;
const label2 = Questions[2].answers[1].answer;
const label3 = Questions[2].answers[2].answer;
const data = [
{
label: label1,
},
{
label: label2,
},
{
label: label3,
},
];
return (
<RadioButtonRN
data={data}
selectedBtn={(e) => console.log(e)}
box={false}
circleSize={14}
activeColor={'#6175CF'}
style={styles.radio}
/>
);
};
export default Radio;
您可以直接使用 javascript 的localStorage
从 session 存储和获取值。 setSelectedRadioBtn
通过名称radioBtn 设置存储中的值, getSelectedRadioBtn
获取存储在存储中的值
setSelectedRadioBtn = (selectedBtn) => localStorage.setItem('radioBtn', selectedBtn);
getSelectedRadioBtn = () => console.log(localStorage.getItem('radioBtn'));
return (
<RadioButtonRN
data={data}
selectedBtn={(e) => setSelectedRadioBtn(e)}
box={false}
circleSize={14}
activeColor={'#6175CF'}
style={styles.radio}
/>
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.