jhen0409 / react-native-boilerplate

The React Native, Redux boilerplate for personal usage
MIT License
246 stars 80 forks source link

Pass argument to function called in component #22

Closed cxk280 closed 6 years ago

cxk280 commented 6 years ago

I'm trying to pass arguments from a component through to a reducer, but after trying everything I can think of, I am still unable to do so. I'll use the unchanged boilerplate's Counter component as an example.

My current solution has this and works fine:

<TouchableHighlight onPress={increment}>
<Text style={styles.text}>+</Text>
</TouchableHighlight>

However, I want to pass arguments, which would look like this:

<TouchableHighlight onPress={increment(argument)}>
<Text style={styles.text}>+</Text>
</TouchableHighlight>

The latter doesn't work. The function is undefined. How do I fix this?

cxk280 commented 6 years ago

It looks like the answer was to use an arrow function, like this:

(argument)=>increment(argument)