From 60a04d6753288e9347946ebdca8a8bffb6dc3763 Mon Sep 17 00:00:00 2001 From: Joel DSouza Date: Fri, 30 Apr 2021 12:06:08 +0530 Subject: [PATCH 1/8] Added contentWillUnmount to call before unmounting --- src/Content.jsx | 7 ++++++- src/Frame.jsx | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Content.jsx b/src/Content.jsx index 2b4262b..bc17267 100644 --- a/src/Content.jsx +++ b/src/Content.jsx @@ -5,7 +5,8 @@ export default class Content extends Component { static propTypes = { children: PropTypes.element.isRequired, contentDidMount: PropTypes.func.isRequired, - contentDidUpdate: PropTypes.func.isRequired + contentDidUpdate: PropTypes.func.isRequired, + contentWillUnmount: PropTypes.func.isRequired }; componentDidMount() { @@ -16,6 +17,10 @@ export default class Content extends Component { this.props.contentDidUpdate(); } + componentWillUnmount() { + this.props.contentWillUnmount(); + } + render() { return Children.only(this.props.children); } diff --git a/src/Frame.jsx b/src/Frame.jsx index 0496920..4b1d295 100644 --- a/src/Frame.jsx +++ b/src/Frame.jsx @@ -16,6 +16,7 @@ export default class Frame extends Component { mountTarget: PropTypes.string, contentDidMount: PropTypes.func, contentDidUpdate: PropTypes.func, + contentWillUnmount: PropTypes.func, children: PropTypes.oneOfType([ PropTypes.element, PropTypes.arrayOf(PropTypes.element) @@ -29,6 +30,7 @@ export default class Frame extends Component { mountTarget: undefined, contentDidMount: () => {}, contentDidUpdate: () => {}, + contentWillUnmount: () => {}, initialContent: '
' }; @@ -89,12 +91,14 @@ export default class Frame extends Component { const contentDidMount = this.props.contentDidMount; const contentDidUpdate = this.props.contentDidUpdate; + const contentWillUnmount = this.props.contentWillUnmount; const win = doc.defaultView || doc.parentView; const contents = (
{this.props.children}
@@ -121,6 +125,7 @@ export default class Frame extends Component { delete props.mountTarget; delete props.contentDidMount; delete props.contentDidUpdate; + delete props.contentWillUnmount; return (