Last active
December 2, 2022 22:25
-
-
Save mitchgollub/0c0e64afe3a4b8e354de58769677a8ae to your computer and use it in GitHub Desktop.
React: High Order Components 3
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
const Profile = ({ username, age }) => ( | |
<div> | |
<div>Username: {username}</div> | |
<div>Age; {age}</div> | |
</div> | |
); | |
Profile.propTypes = { | |
username: string, | |
age: number | |
}; | |
// Usage - wrapping the component with the function | |
const withFlattenUser = flattenProp('user'); | |
const ProfileWithFlattenUser = withFlattenUser(Profile); | |
// OR | |
const ProfileWithFlattenUser = flattenProp('user')(Profile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment