I have a modal parent component and a form child component. The function that opens and closes the modal is in the parent, but the submit function is in the child. What I want to do is to close the modal on submit, but for that I need the submit function from the child to trigger the close modal function from the parent. I know how to pass a function from < Parent />
to < Child />
, but in here the difference is that the child is returned in the parent in this form {children}
. How can I do this when the child is returned in this form ?
This is the modal component or the parent:
<ModalInMobile
id="SearchFiltersMobile.filters"
isModalOpenOnMobile={this.state.isFiltersOpenOnMobile}
onClose={this.cancelFilters}
showAsModalMaxWidth={showAsModalMaxWidth}
onManageDisableScrolling={onManageDisableScrolling}
containerClassName={modalContainerStyles}
closeButtonMessage={modalCloseButtonMessage}
>
<button className={showListingsButtonStyles} onClick={this.closeFilters}>
X
</button>
{this.state.isFiltersOpenOnMobile ? (
<div className={modalFilterWrapperStyles}>{children[this.state.renderingModals]}</div>
) : null}
</ModalInMobile>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…