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

172
Views
Reaccionar funciones de llamadas nativas y cambiar estados de un componente

Entonces, actualmente tengo una función que representa un componente NewButton , en ese componente, ¿cómo llamo a la función toggleModalVisibility , que se define fuera de ese componente? Esa función cambiará muchos estados y llamará a otras funciones, y también cambiará la representación.

 import React, { useState, useEffect} from 'react' import {Button, View, Text, StyleSheet,TextInput,ScrollView, Modal} from 'react-native' import { BottomSheet } from 'react-native-btr'; import NewButton from './NewButton' export default function CardFolder({navigation, navigation: {setOptions}}){ const [visible, setVisible] = useState(false); //many other states const toggleModalVisibility = () => { //changes states, calls other functions, change rendering, Toggle bottomSheet }; return( < > <Modal> modal containing a text field, change states </Modal> <BottomSheet>contains other options, upload something to db</BottomSheet> <View style = {{flex:1}}> <NewButton style = {{bottom: 50}} /> </View> </> ) }

El componente:

 import {View, Button} from 'react-native' export default class NewButton extends React.Component { return( <View style = {[styles.container,this.props.style]}> //how do I call the functon toggleModalVisibility here? <Button onPress={toggleModalVisibility}/> </View> ) } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

puede agregarlo como accesorio al componente NewButton

 <NewButton style={{bottom: 50}} toggleModalVisibility={toggleModalVisibility} />

y la llaman como

 <Button onPress={this.props.toggleModalVisibility}/>
about 4 years ago · Juan Pablo Isaza Report

0

Como le sugirió @Krosf, debe pasar la función por accesorios y luego llamar a la función cuando se presiona el botón, en su caso está usando el componente de clase, por lo que debe usar la palabra clave " este " para acceder a sus " accesorios NewButton "

como esto:

 <Button onPress={ this.props.toggleModalVisibility } />
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!