You might try a useEffect
hook subscribed to the attributes.identifier
to call the script.
something like:
function Edit( { attributes, setAttributes } ) {
useEffect( () => {
// this will fire whenever the attribute changes.
thirdPartyScriptFunctionName();
},[attributes.identifier])
const onChangeIdentifier = (value) => {
setAttributes({ identifier: value });
};
return (
<div id = {`embed-${ instanceId }`}>
{attributes.identifier
?
<div
data-identifier= { attributes.identifier }
>
</div>
:
<Placeholder
instructions={ __( 'Enter identifier.' ) }
>
<PlainText
placeholder={ __(
'Enter identifier here…'
) }
value={ attributes.identifier || '' }
onChange={ onChangeIdentifier }
/>
</Placeholder>
}
</div>);
}
export default withInstanceId( Edit );
You’ll need to get the useEffect
hook from the wp.element global.
Hope this helps!