Javascript React本机无线电表单初始值未更新
我使用我的状态变量设置无线电表单的初始值。它的初始值未定义,然后该值更改为1,但在页面中始终显示“是”Javascript React本机无线电表单初始值未更新,javascript,react-native,Javascript,React Native,我使用我的状态变量设置无线电表单的初始值。它的初始值未定义,然后该值更改为1,但在页面中始终显示“是” import RadioForm from 'react-native-simple-radio-button'; ... render() { const radio_props = [ {label: 'Yes ', value: 0 }, {label: 'No', value: 1 } ]; const test = this.state
import RadioForm from 'react-native-simple-radio-button';
...
render() {
const radio_props = [
{label: 'Yes ', value: 0 },
{label: 'No', value: 1 }
];
const test = this.state.myValue;
console.log(test);
...
<RadioForm
radio_props={radio_props}
initial={test}
formHorizontal={true}
labelHorizontal={true}
buttonColor={'#2196f3'}
animation={true}
buttonSize={15}
onPress={(text) => this.onChangeSettings(text, 'Test')}
/>
}
未定义的状态是否会产生问题?而您可以保留未定义的初始状态。最好将初始状态设置为-1之类的值。然后执行以下操作:
{this.state.test != -1 &&
<RadioForm
radio_props={radio_props}
initial={test}
formHorizontal={true}
labelHorizontal={true}
buttonColor={'#2196f3'}
animation={true}
buttonSize={15}
onPress={(text) => this.onChangeSettings(text, 'Test')}
/>
}
{this.state.test!=-1&&
this.onChangeSettings(文本“Test”)}
/>
}
{this.state.test != -1 &&
<RadioForm
radio_props={radio_props}
initial={test}
formHorizontal={true}
labelHorizontal={true}
buttonColor={'#2196f3'}
animation={true}
buttonSize={15}
onPress={(text) => this.onChangeSettings(text, 'Test')}
/>
}