lundi 2 juillet 2018

How to push item to array if checked in React Native?

I am mapping an array and checking with checkbox. But I checking it in customCheckbox. I want to push checked items to involvedfriends:[]

How can I call checked state from Checkbox, and add checked item to array

But I not quite sure how i will achieve it, hope someone can help me.

My state

state={involvedFriends:[]}

AddFriendScreen

{this.state.involvedFriends.map((name, key) => (
        <View>
          <CustomCheckbox name={name}/>
        </View>
      ))}

CustomCheckbox

this.state = {
  checked: false,
};

toggleChange = () => {
     this.setState({ checked: !this.state.checked })};

render() {
return (
  <View style={styles.container}>
    <Text style={styles.text}>{this.props.name}</Text>
    <CheckBox
      checked={this.state.checked}
      onPress={() => this.toggleChange()}
    />
  </View>
)}




Aucun commentaire:

Enregistrer un commentaire