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

Time:05-20

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?

CodePudding user response:

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

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

CodePudding user response:

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

  • Related