Created
November 25, 2020 14:48
-
-
Save mqklin/f5235c31a5514efbb11bc8ab13cfe371 to your computer and use it in GitHub Desktop.
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 StakedModal() { | |
const {modal} = ModalContext.useContext(['modal']); | |
const [{ | |
modals, | |
}, ss] = useStateReducer({ | |
modals: [], | |
}); | |
const create = () => { | |
const random = getUniqueNumber(); | |
ss(state => ({modals: [...state.modals, random]})); | |
modal.add({ | |
contentEl: ( | |
<div style={{background: 'white', width: '100px', height: `${Math.random() * 3000}px`, display: 'flex', alignItems: 'flex-end'}}> | |
<button onClick={create}>{random}</button> | |
</div> | |
), | |
id: random, | |
isCloseCrossHidden: true, | |
onRemove: () => ss(state => ({modals: state.modals.filter(id => id !== random)})), | |
}); | |
}; | |
useEffect(() => { | |
setTimeout(() => { | |
create(); | |
}, 1000); | |
}, []); | |
return ( | |
<> | |
{modals.map(id => modal.get(id))} | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment