Created
December 27, 2023 21:30
-
-
Save jasloe/7e461978b14314f13ea2358e712555bf to your computer and use it in GitHub Desktop.
Example HOC
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'; | |
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