当我点击外面时,我想要一个模态关闭。在下面的代码中,您可以找到handleCloseClick函数以及render方法。
如何在React中执行此操作?
handleCloseClick = (e) => {
const { hideModal } = this.props
e.preventDefault()
hideModal()
}
我尝试将道具传递给关闭的组件是CustomModal。
render() {
const { connectDropTarget } = this.props
return (
<CustomModal
alternateModalClass='c-group-stickies-modal'
onClosePress={this.handleCloseClick}
alternateCloseButtonClass='c-group-stickies-modal__close-button'
>
{this.renderModalHeading()}
<CustomModal.Content
alternateContentClass='c-group-stickies-modal__content'
>
{connectDropTarget(
<div className='c-group-stickies-modal__stickies'>
<Masonry
className={'my-gallery-class'}
onClick={this.handleClick}
>
{this.renderGroupStickies()}
</Masonry>
</div>
)}
</CustomModal.Content>
</CustomModal>
)
}