My react-native app has several situations where different modals can be presented. I am wondering what's the best way to accomplish this. In general I see two different approaches:
a)
On the root view I always have the Modal
-component mounted and simply switch the content, like this...
<View>
{...}
<Modal visible={this.props.modal > 0}>
{this.props.modal === 1 && <ModalContent1 />}
{this.props.modal === 2 && <ModalContent2 />}
{this.props.modal === 3 && <ModalContent3 />}
</Modal>
</View>
b) Every modal brings it's own Modal
-component and is mounted somewhere in the tree, near the place it is triggered from.
Which way would you prefer and why?
A question that applies to both approaches is, if the Modal
-component should always be mounted and only triggered using the visible
-prop. If that's the way to go, I assume approach b) needs more memory, because multiple instances of the Modal
-component are created.