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

185
Views
Pasar estado de padre a hijo a hijo

Sé que estoy cerca de hacer que esto funcione, pero algo está mal. Estoy tratando de pasar un estado de un componente principal a un elemento secundario y luego a otra función secundaria. Tengo una demostración que explica exactamente lo que estoy tratando de lograr aquí . La palabra/botón Mapa y Lista debería cambiar las pantallas.

También daré el código a continuación, pero recomiendo la demostración de trabajo anterior.

 export default class App extends React.Component { constructor(props) { super(props); this.state = { whichComponentToShow: "Screen1" }; } goToMap = () => { this.setState({ whichComponentToShow: "Screen2" }); }; goToList = () => { this.setState({ whichComponentToShow: "Screen1" }); }; render() { const { whichComponentToShow } = this.state; return ( <View style={{padding: 40,backgroundColor: whichComponentToShow === "Screen1" ? "aquamarine" : "aqua", flex: 1}}> <Text style={{fontSize: 20}}> Home - Class Component - {this.state.whichComponentToShow} </Text> <ListHome renderMap={this.goToMap} renderList={this.goToList}/> </View>
 export default class ListHome extends React.Component { render() { return ( <View style={{ backgroundColor: "#ddd", padding: 10 }}> <Text>ListHome</Text> <Slider renderMap={this.props.renderMap} renderList={this.props.renderList} /> </View>
 const Slider = (props) => { return ( <View style={{ backgroundColor: "#ccc", flex: 1 }}> <Text>Slider</Text> <TouchableOpacity onPress={() => {props.renderMap; }}> <Text> Map </Text> </TouchableOpacity> <TouchableOpacity onPress={() => {props.renderList; }}> <Text> List </Text> </TouchableOpacity> </View> ); };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Su componente Slider debería usar sus accesorios de esta manera:

 import * as React from 'react'; import { Text, View, StyleSheet, Button, TouchableOpacity} from 'react-native'; const Slider = (props) => { return ( <View style={{ backgroundColor: "#ccc", flex: 1 }}> <Text>Slider</Text> <TouchableOpacity onPress={props.renderMap}> <Text> Map </Text> </TouchableOpacity> <TouchableOpacity onPress={props.renderList}> <Text> List </Text> </TouchableOpacity> </View> ); }; export default Slider;
about 4 years ago · Juan Pablo Isaza Report

0

En Slider.js, cambie la llamada del botón a - onPress= {()=>props.renderMap()}

 const Slider = (props) => { return ( <View style={{ backgroundColor: "#ccc", flex: 1 }}> <Text>Slider</Text> <TouchableOpacity onPress={() =>props.renderMap()}> <Text> Map </Text> </TouchableOpacity> <TouchableOpacity onPress={() => props.renderList()}> <Text> List </Text> </TouchableOpacity> </View> ); };
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!