在React Native

时间:2019-01-09 10:21:14

标签: javascript reactjs react-native checkbox

我一直在用react native开发一个表单,该表单具有一个复选框。因此,预期的行为是当用户单击他接受的用于保存地址的复选框时,以及当用户再次按下该复选框时,选中状态应为false。如何实现使用状态?我的复选框代码:

            <CheckBox
                    title='Save this Address for further use.'
                    containerStyle={{backgroundColor:'transparent', 
                    borderColor: 'transparent'}}
                    textStyle={{ fontSize: 10 }}
                    onPress={() => this.props.userDetailsCreate({ 
                    prop:'saveThisAddress', value: 'true' })}
                    checked={this.props.saveThisAddress ? true : false}
                    //checked={this.state.checked}
                />

通过以上代码,我可以使用户单击并标记为选中状态。但是,当用户再次单击复选框时,如何更改为默认未选中状态?当我使用redux状态时,解决方案可以是redux或组件级别的状态!请指导

0 个答案:

没有答案