generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Eliminada la repetición del código * Extraída la funcionalidad del temporizador a un nuevo componente * Eliminada la opción de Juego desde la navegación
- Loading branch information
Showing
3 changed files
with
58 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
const Temporizador =({tiempoInicial, tiempoAcabado, pausa})=> { | ||
|
||
//Constante que va restando segundos | ||
const [tiempoSegundos, setTiempoSegundos] = useState(tiempoInicial); | ||
|
||
|
||
useEffect(() => { | ||
let intervalID; | ||
|
||
if (tiempoSegundos > 0 && !pausa) { | ||
intervalID = setInterval(() => { | ||
setTiempoSegundos((prevTiempo) => prevTiempo - 1); | ||
}, 1000); | ||
} | ||
if(tiempoSegundos<=0) | ||
tiempoAcabado(); | ||
return () => clearInterval(intervalID); | ||
}, [tiempoSegundos, pausa]); | ||
|
||
return ( | ||
<div className="temporizador"> <p> {tiempoSegundos} </p> </div> | ||
) | ||
} | ||
|
||
export default Temporizador; |