mercredi 19 septembre 2018

how can i dynamically bind each state to each checkbox when using map function

I m doing something like this but the value is been taken as string and not as a variable with boolean value

        {question.data.map((value, i) => (
            <View style=>
                <CheckBox value={`this.state.checked${i}`} onValueChange={() => this.toggleCheckBox(i)} />
                <Text>{value.question}</Text>
            </View>
            ))
        }

this is my toggleCheckBox method

      toggleCheckBox(i) {
         this.setState({ [`checked${i}`]: ![`this.state.checked${i}`] });
      }

need help.




Aucun commentaire:

Enregistrer un commentaire