Skip to content

Instantly share code, notes, and snippets.

@mitchgollub
Last active December 2, 2022 22:25
Show Gist options
  • Save mitchgollub/0c0e64afe3a4b8e354de58769677a8ae to your computer and use it in GitHub Desktop.
Save mitchgollub/0c0e64afe3a4b8e354de58769677a8ae to your computer and use it in GitHub Desktop.
React: High Order Components 3
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