Skip to content

Instantly share code, notes, and snippets.

@Angelmmiguel
Created April 21, 2023 20:09
Show Gist options
  • Save Angelmmiguel/2de20de04e1fc15caf81777452977ab8 to your computer and use it in GitHub Desktop.
Save Angelmmiguel/2de20de04e1fc15caf81777452977ab8 to your computer and use it in GitHub Desktop.
Ejemplo de uso de selectores en Redux
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