Skip to content

Commit

Permalink
Add optional onHide/onShow hooks to Switch component
Browse files Browse the repository at this point in the history
- Allows functions to be specified to run when Switch is shown/hidden
  • Loading branch information
jdlehman committed Apr 4, 2015
1 parent 97f9561 commit 14aafea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/switcheroo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion modules/components/Switch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import React, {Component} from 'react';

export default class Switch extends Component {
componentDidMount() {
if(typeof this.props.onShow === 'function') {
this.props.onShow();
}
}

componentWillUnmount() {
if(typeof this.props.onHide === 'function') {
this.props.onHide();
}
}

render() {
return React.createElement(this.props.handler, this.props.handlerProps);
}
Expand All @@ -11,5 +23,7 @@ Switch.displayName = 'Switch';
Switch.propTypes = {
path: React.PropTypes.string.isRequired,
handler: React.PropTypes.func.isRequired,
handlerProps: React.PropTypes.object
handlerProps: React.PropTypes.object,
onShow: React.PropTypes.func,
onHide: React.PropTypes.func
};

0 comments on commit 14aafea

Please sign in to comment.