Skip to content

Instantly share code, notes, and snippets.

@ravewebdev
Last active July 9, 2020 17:33
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 ravewebdev/b461ed20854868c18c1663e52ee05990 to your computer and use it in GitHub Desktop.
Save ravewebdev/b461ed20854868c18c1663e52ee05990 to your computer and use it in GitHub Desktop.
1.1.2. Set the ID attribute value
registerBlockType( 'rave/initiative-tracker', {
// Code from 1.1.1. and other block properties here...
edit: ( props ) => {
const {
attributes: {
id,
},
clientId,
setAttributes,
} = props;
useEffect( () => {
// If id is not set (initial block creation), set id to clientId value.
if ( 0 === id.length ) {
setAttributes( {
id: clientId,
} );
}
}, [] );
},
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment