Created
June 23, 2017 03:25
-
-
Save treyhoover/9162329effbfc578756402f0d501110a 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
export default withPassThroughProps({ | |
whiteList: false, /* blacklist these props */ | |
propNames: [...brands, ...sizes], | |
})(SomeComponent); |
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 from "react"; | |
const withPassThroughProps = | |
({ | |
whiteList, | |
propNames = [], | |
as = "passThroughProps" | |
}) => ComposedComponent => props => { | |
const input = new Set(propNames); | |
const keys = Object.keys(props); | |
const passThroughProps = keys.reduce((obj, key) => { | |
if (input.has(key) === whiteList) obj[key] = props[key]; | |
return obj; | |
}, {}); | |
const newProps = { [as]: passThroughProps }; | |
return <ComposedComponent {...props} {...newProps} /> | |
}; | |
export default withPassThroughProps; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment