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

183
Views
Cómo acceder a un estado modificado desde un archivo diferente

Estoy tratando de acceder a una matriz que se modifica desde Screen1. ¿Cómo puedo obtener acceso a esta matriz desde Screen2? ¿Hay alguna forma de hacer esto?

Pantalla1.tsx

 function Screen1() { const getData = () => { data = [1, 2, 3, 4, 5] data.filter((i) => i < 3) return data; } return ( <View> <Text>Returning JSX</Text> </View> ) }

Pantalla2.tsx

 const Screen2 = ({ navigation }) => { const arr = [1, 2] // modified arr from screen 1 return ( {arr.map((i) => ( <Button onPress={() => navigation.navigate("Screen1") } /> ))} ) }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puedes hacerlo pasando accesorios de la screen1 a la screen2

Prueba este código, ¡está funcionando!

// Pantalla1

 import React, { useState } from "react"; import Screen2 from './Screen2'; function Screen1() { var [arr, setArr] = useState([1, 2, 3, 4, 5]); return ( <div> <Screen2 data={arr} /> </div> ); } export default Screen1;

//Pantalla2

 import React, { useState } from "react"; function Screen2(props) { return ( <div>{props.data}</div> ); } export default Screen2
about 4 years ago · Juan Pablo Isaza Report

0

Debe enviar arr al componente Screen2

Por ejemplo:

Pantalla1.tsx

 function Screen1() { var [arr, setArr] = useState([]); data = [1, 2, 3, 4, 5]; setArr(data); retrun(<Screen2 data = {arr}>) }

Pantalla2.tsx

 const Screen2 = (props) => { console.log(props.data);//[1, 2, 3, 4, 5] retrun(<div></div>); }
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!