Add a `keepMounted` option
Motivation
By default, all modals continue to be mounted even when they are closed. Despite of that it's giving some advantages, sometimes it may be required to unmount it.
For example, the modal can contain a state machine that will continue working after closure, which may be unintentional.
Description
keepMounted will be added to ModalParams, so developers can disable it for single modal or all modals by default.
Example 1
Modal.open(Component, { keepMounted: false })
Example 2
const Modal = new ModalController({
default: { keepMounted: false }
})
Modal.open(Component)
These two modals will have the same behavior.
This is related to caching.
Hi! I really really need that feature, how can i help?
@dientuki Hi, sorry for a late response, I actually wanted to work on this feature when new React Visibility API is fully there.
But we can start working on it now.
What we need is to make sure the component is mounted while not visible, we can probably use hidden attribute or display: none style.
But this feature will be a breaking change since, it makes ANY component to be always mounted, so I believe we should set keepMounted to false by default.
- If this is overridden to
truein the default settings, it should keep mounted all open components - If this is overridden to
truein the local open params, it should keep mounted the opened component
Hope this helps, I'm currently busy with other staff, so hope you'll figure out how to implement this yourself. I will try to review the PR ASAP.
Related to https://github.com/FrameMuse/react-modal-global/issues/258