Answer the question
In order to leave comments, you need to log in
How to start rendering components from MobX map react?
To allow multiple modal windows to be used at the same time, I put them in observable.map() like this
@observable modals = observable.map();
@action('add modal')
addModal = component => {
const id = createGuid();
this.modals.set(id, component);
};
@action
removeModal = id => {
this.modals.delete(id);
};
newModal = close => {
return (
<ModalWrap>
<Overlay onClick={close} />
<Body>
<div>content</div>
<Close action={close}>❌</Close>
</Body>
</ModalWrap>
);
};
<>
{modals.entries().map(({ id, modal }) => (
<React.Fragment key={id}>
{modal(this.onClose(id))}
</React.Fragment>
))}
</>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question