Created
December 26, 2018 04:44
-
-
Save rajatk16/5da3ca690b383bf55e1678c2d553ec81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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