Hefaz
Hefaz

Reputation: 671

How to call multiple functions with onPress, which has its own parameter in React Native?

I am trying to call multiple functions when onPress is called in React Native. The problem is that where I call the functions, that function itself has a handlePress parameter. Here is the code:

const _renderTruncatedFooter = (handlePress) => {
      return (
        <Button
        accessoryLeft={MoreIcon}
        appearance='ghost'
        status='control'
        size = 'medium'
        style={styles.button}
        onPress={()=>{handlePress, storeRead(item), changeTitleColor();}} >
        {i18n.t('ShowMore')}
        </Button>
      );
  }

the other two functions, that I want to call are:

const storeRead = async (value) => {
  try {
    const jsonValue = JSON.stringify(value)
    await AsyncStorage.setItem('read_data', jsonValue)
    alert('data saved')

  } catch (e) {
    alert('Failed to save the data to the storage')
  }
}

and the second one is:

const changeTitleColor = () => {
  setRead(true);
}

But this is not working. How can I achieve this?

Upvotes: 1

Views: 871

Answers (2)

Pushpendra Chouhan
Pushpendra Chouhan

Reputation: 42

call one function in on press like sectionOne

so in section one, you can call your all rest function

not call all functions in onPress

Upvotes: 0

iChwan
iChwan

Reputation: 53

don't use comma inside your onPress props, just do like this

onPress={() => {
   handlePress();
   storeRead(item);
   changeTitleColor();
}}

Upvotes: 3

Related Questions