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

368
Views
How can calling parent function from child component and passing parameters from child component to parent component in React Native?

I make a function with 12 arguments in the parent screen and call that function from the child component and pass parameters from a child but it is not working and rerender the screen unlimited time.

For example:

// This is my Array:
    const [DataArray, setDataArray] = useState([
        {
          title: 'Saudi Arabia',
          guest: '2 Guests',
          description: 'This is my Description',
          location: 'Riadh, KSA',
          estimateCost: '$1000',
          duration: '1 Month',
          groupSize: 'small',
          hostedIn: 'Michigan',
          includes: '2 Return Tickets',
          date: '12 July 2022',
          notes: 'N/A',
          locationDetails: 'House # 12, Makhdoom street, Al-Riadh, KSA',
        },
      ]);

Parent Screen Function:

// Add cards function.
  const AddCard = (a, b, c, d, e, f, g, h, i, j, k, l) => {
    let array = DataArray;
    array.unshift({
      title: a,
      guest: b,
      description: c,
      location: d,
      estimateCost: e,
      duration: f,
      groupSize: g,
      hostedIn: h,
      includes: i,
      date: j,
      notes: k,
      locationDetails: l
    });
    setDataArray(array);
    modalVisibleOff;
  };

Child Component from where I calling Function

<TouchableOpacity
                onPress={AddCard(
                  Title,
                  Guest,
                  Description,
                  Location,
                  EstimateCost,
                  Duration,
                  GroupSize,
                  HostedIn,
                  Includes,
                  Date,
                  Notes,
                  LocationDetails,
                )}
                style={styles.Button}>
                <Text style={styles.ButtonText}>Submit</Text>
              </TouchableOpacity>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your child component you are calling AddCart function immediately. Here is the updated code

<TouchableOpacity
    onPress={() => AddCard(
      Title,
      Guest,
      Description,
      Location,
      EstimateCost,
      Duration,
      GroupSize,
      HostedIn,
      Includes,
      Date,
      Notes,
      LocationDetails,
    )}
    style={styles.Button}>
    <Text style={styles.ButtonText}>Submit</Text>
</TouchableOpacity>

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!