Skip to content

Instantly share code, notes, and snippets.

@rajatk16
Created December 26, 2018 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajatk16/5da3ca690b383bf55e1678c2d553ec81 to your computer and use it in GitHub Desktop.
Save rajatk16/5da3ca690b383bf55e1678c2d553ec81 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
import PropTypes from 'prop-types'
import {defaultTo} from 'lodash';
class HideOrShow extends Component {
constructor(props) {
super(props);
this.state = {
isVisible: defaultTo(props.initialState, false),
};
this.hide = this.hide.bind(this);
this.show = this.show.bind(this);
}
hide() {
this.setState({
isVisible: false
});
}
show() {
this.setState({
isVisible: true
});
}
render() {
return this.props.children({
...this.state,
hide: this.hide,
show: this.show,
});
}
}
HideOrShow.PropTypes = {
initialState: PropTypes.bool,
children: PropTypes.func.isRequired
};
export default HideOrShow;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment