Created
April 21, 2023 20:09
-
-
Save Angelmmiguel/2de20de04e1fc15caf81777452977ab8 to your computer and use it in GitHub Desktop.
Ejemplo de uso de selectores en Redux
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
import Modal from "./Modal"; | |
import { useState } from "react"; | |
import { useSelector } from "react-redux"; | |
import { getUser, getTime } from "../selectors/connection" | |
import store from "../store"; | |
const ConnectionData = () => { | |
const [showModal, setShowModal] = useState(false); | |
// Es necesario utilizar el hook useSelector para acceder al | |
// estado actual | |
const user = useSelector((state) => state.connection.user); | |
const time = useSelector((state) => state.connection.time); | |
// const closeModal = () => { | |
// setShowModal(false); | |
// } | |
return ( | |
<section> | |
<h3>Tu conexión actual:</h3> | |
<Modal show={showModal} onClose={() => setShowModal(false)}> | |
{/* <Modal show={showModal} onClose={closeModal}></Modal> */} | |
<h4>{"Estado conexión: " + user != "" ? "Conectado" : "Desconectado"}</h4> | |
{ user != "" && <> | |
<h4>{"Usuario: " + user}</h4> | |
<h4>{"Hora última conexión: " + time}</h4> | |
</>} | |
<button onClick={() => setShowModal(false)}>Aceptar</button> | |
</Modal> | |
</section> | |
); | |
} | |
export default ConnectionData; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment