Skip to content

Instantly share code, notes, and snippets.

@mqklin
Created November 25, 2020 14:48
Show Gist options
  • Save mqklin/f5235c31a5514efbb11bc8ab13cfe371 to your computer and use it in GitHub Desktop.
Save mqklin/f5235c31a5514efbb11bc8ab13cfe371 to your computer and use it in GitHub Desktop.
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