Last active
July 9, 2020 17:33
-
-
Save ravewebdev/b461ed20854868c18c1663e52ee05990 to your computer and use it in GitHub Desktop.
1.1.2. Set the ID attribute value
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
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