Class pass function

Asked

Viewed 54 times

-1

I need to use the same button on different pages and with different functions

How can I pass the function to the button ?

class App extends Component {
   render(){
      return(
        <View>
           <Button title="Abrir conta" />
        </View>
      )
   }
}

const Button = (props) => (
   <View>
      <TouchableOpacity onPress={() => {}}>
         <Text>{props.title}</Text>
      </TouchableOpacity>
   </View>
)
  • Your question is a little vague. Could you edit it by adding a little more detail, please? :)

1 answer

2


class App extends Component {
   render(){
      return(
        <View>
           <Button title="Abrir conta" onPress={()=> this._something()} />
        </View>
      )
   }
}

export default Button = (props) => (
   <TouchableOpacity onPress={props.onPress}>
      <Text>{props.title}</Text>
   </TouchableOpacity>
)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.