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

1.1K
Views
¿Cómo destruir el componente o detener su ejecución cuando la ruta cambia usando React-Native?

Estoy creando un componente de cuenta regresiva simple con React-Native y usando este paquete react-native-countdown-component , quiero destruir este componente de Timer o detener su ejecución cuando cambie la pantalla enfocada, para la navegación inferior estoy usando React-Native Tab navigation , ¿cuál es la mejor solución para lograr este resultado?

 import { MaterialCommunityIcons } from "@expo/vector-icons"; import React, { useEffect, useState } from "react"; import { View } from "react-native"; import CountDown from "react-native-countdown-component"; const Timer: React.FC<{ expirationDate: number }> = ({ expirationDate }) => { const [timer, setCurrentTime] = useState<number>(expirationDate); const [inactive, setIncative] = useState(false); return ( <View style={{ backgroundColor: timer < 300 || inactive ? "#edbcbc" : "#cee5f4", width: 70, borderRadius: 7, paddingVertical: 6, flexDirection: "row", alignItems: "center", justifyContent: "center", position: "relative", }} > <View style={{ position: "relative", left: 4 }}> <MaterialCommunityIcons name="timer-outline" size={13} color={timer < 300 || inactive ? "#f54c4c" : "#004978"} /> </View> <CountDown until={timer} timeToShow={["M", "S"]} timeLabels={false} digitStyle={{ backgroundColor: "#f5f5f500" }} separatorStyle={{ color: "#004978", fontSize: 10 }} digitTxtStyle={{ color: timer < 300 || inactive ? "#f54c4c" : "#004978" }} onFinish={() => setIncative(true)} size={9} running={timer ? true : false} showSeparator /> </View> ); }; export default Timer;

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

la función useEffect le permite devolver una función que se llama cuando se desmonta un componente. podría usar eso o llamar a algo cuando cambie la pestaña.

over 4 years ago · Santiago Trujillo Report

0

El componente CountDown administra el temporizador en sí mismo y el autor de la biblioteca logra borrar el temporizador cuando el componente se desmonta https://github.com/talalmajali/react-native-countdown-component/blob/master/index.js#L58

over 4 years ago · Santiago Trujillo Report

0

por favor lea este enlace:

https://github.com/talalmajali/react-native-countdown-component/blob/master/index.js#L58

si tienes alguna pregunta puedes hacerla

over 4 years ago · Santiago Trujillo 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!