Last active
July 23, 2023 04:47
-
-
Save Hiweus/b8f4abcdd8b72986eed065a1f44e2c0f to your computer and use it in GitHub Desktop.
React components
This file contains hidden or 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
function debouncer(fn, miliseconds) { | |
let timer = null | |
return (...args) => { | |
clearTimeout(timer) | |
timer = setTimeout(() => fn(...args), miliseconds) | |
} | |
} |
This file contains hidden or 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 { useState } from 'react' | |
import { Modal } from 'react-bootstrap' | |
function FullModal({ children, title, show, onClose }) { | |
return ( | |
<Modal show={show} fullscreen={true} onHide={onClose}> | |
<Modal.Header closeButton> | |
<Modal.Title>{title}</Modal.Title> | |
</Modal.Header> | |
<Modal.Body> | |
{children} | |
</Modal.Body> | |
</Modal> | |
) | |
} | |
function useModal() { | |
const [show, setShow] = useState(false) | |
return [ | |
show, | |
() => setShow(true), | |
() => setShow(false), | |
] | |
} | |
// USANDO OS COMPONENTES | |
function App() { | |
const [show1, open1, close1] = useModal() | |
const [show2, open2, close2] = useModal() | |
const [o, setO] = useState(null) | |
return ( | |
<div> | |
<button onClick={() => { | |
open1() | |
open2() | |
setO({ nome: 'João' }) | |
}}> | |
Travar | |
</button> | |
<FullModal title='Modal 1' show={show1} onClose={close1}> | |
<p>Conteúdo do modal 1</p> | |
<div> | |
Amigo estou aqui | |
</div> | |
</FullModal> | |
<FullModal title='Modal 2' show={show2} onClose={close2}> | |
{o && ( | |
<> | |
<p>Conteúdo do modal 2</p> | |
<div> | |
Amigo estou aqui {o.nome} | |
</div> | |
</> | |
)} | |
</FullModal> | |
</div> | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment