react-hocs
Higher Order Component Utilities for React Components
Installation
yarn add react-hocs
Usage
Full Example:
// ----- READ USER COMPONENT ----- // static defaultProps = href: string user: null isReady: false // Do some cool loading stuff here using this.props.href { const children isReady user ...rest = thisprops; return React; } const mapStateToProps = { const href = props; return isReady: statenetworksstate === RESOLVED user: statenetworkseveryone ;}; const connectReadUser = ; ;; // ----- I NEED A USER COMPONENT ----- // { if !thispropsuserReady return null; return <div> thispropsuserdatafirst_name </div> ; } const mapStateToProps = { return // Map other data here ;}; // By default, the hocFactory will auto-map props for you, making this redundant // instead, we could use `connectReadUser()` and it would be the same functionality INeedAUser; // ----- APP COMPONENT ----- // { return <INeedAUser href="/users/123" /> ; }