Chris Henry
Chris Henry

Reputation: 199

How do I pass a var to onPress?

I am trying to get a value/string from a JSON file which is assigned to a, that can then be passed to handleAnswerQuestion.

Error message

var a = { myData.results[count].category[count] }

<TrueButton onPress={() => this.handleAnswerQuestion(a)}>

const TrueButton = styled.TouchableOpacity`
  padding: 15px 25px 15px 25px;
  border-radius: 50;
  backgroundColor: rgba(106,227,104, 0.8);
`

Upvotes: 1

Views: 48

Answers (1)

Nirmalsinh Rathod
Nirmalsinh Rathod

Reputation: 5186

You need to pass value on your custom class TrueButton. And then you can pass like this:

<TrueButton onPress={(valueFromCustomClass) => this.handleAnswerQuestion(valueFromCustomClass)}>

valueFromCustomClass is a value which you passed from your custom class.

Upvotes: 1

Related Questions