Skip to content

Instantly share code, notes, and snippets.

@jasloe
Created December 27, 2023 21:30
Show Gist options
  • Save jasloe/7e461978b14314f13ea2358e712555bf to your computer and use it in GitHub Desktop.
Save jasloe/7e461978b14314f13ea2358e712555bf to your computer and use it in GitHub Desktop.
Example HOC
import React from 'react';
import Layout from '../components/Layout/Layout';
const withLayout = (PageComponent) => {
const WithLayout = (props) => (
<Layout {...props}>
<PageComponent {...props} />
</Layout>
);
// Set a displayName for debugging purposes
const wrappedComponentName = PageComponent.displayName || PageComponent.name || 'Component';
WithLayout.displayName = `withLayout(${wrappedComponentName})`;
return WithLayout;
};
export default withLayout;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment