Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

369
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda