Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Created April 27, 2019 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrocks/fe28845468a0736d310639a87a5775ff to your computer and use it in GitHub Desktop.
Save pbrocks/fe28845468a0736d310639a87a5775ff to your computer and use it in GitHub Desktop.
From the Handbook, creating a higher order component is a best practice for the WordPress abstraction layer of React.
const { createHigherOrderComponent } = wp.compose;
const withClientIdClassName = createHigherOrderComponent( ( BlockListBlock ) => {
return ( props ) => {
return <BlockListBlock { ...props } className={ "block-" + props.clientId } />;
};
}, 'withClientIdClassName' );
wp.hooks.addFilter( 'editor.BlockListBlock', 'my-plugin/with-client-id-class-name', withClientIdClassName );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment