0

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={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'center' }}>
                <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.

1 Answer 1

1

The issue is with adding string interpolation around this.state

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


{question.data.map((value, i) => (
    <View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'center' }}>
    <CheckBox value={this.state[`checked${i}`]} onValueChange={() => this.toggleCheckBox(i)} />
    <Text>{value.question}</Text>
    </View>
    ))
}
Sign up to request clarification or add additional context in comments.

1 Comment

that worked ... thanks a lot for your help. have a nice day. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.