Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
How to execute parent function from child in react native?

I need to execute the parent function from child which is imported. Child component is my button view. Please help to find a solution in parent file:

export default function Home(props) {
    function test(){
        alert("asd")
    }

 <CardheaderSlider name="All" />
                        <CardheaderSlider name="English" />
                        <CardheaderSlider name="Mathematics" />
                        <CardheaderSlider name="Science" />
                        <CardheaderSlider name="Languages" />
                        <CardheaderSlider name="Activity Books" />
                        <CardheaderSlider name="E-Training" />
}

CardheaderSlider file

export default class CardheaderSlider extends React.Component {
    render() {
        return (
            <Pressable style={styles.button}>
                <Text style={{ color: "#fff", fontWeight: "bold" }}>{this.props.name}</Text>
            </Pressable>
        )
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can add onPress attribute on your child:

export default class CardheaderSlider extends React.Component {
    render() {
        return (
            <Pressable style={styles.button} onPress={() => this.props.onPress()}>
                <Text style={{ color: "#fff", fontWeight: "bold" }}>{this.props.name}</Text>
            </Pressable>
        )
    }

And call it like:

<CardheaderSlider name="All" onPress={() => myFunction()}/>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!