How to get the clientId from Edit.js to view.js in Dynamic Block
-
I am saving clientId in the attribute as instnaceId but not sure how would i access that in the view.js file
As i need a unique id for my block so that i can attach my custom react component to it.
Below is what is in my block.json
"attributes": { "instanceId": { "type": "string", "default": "" } }
and this is how i am saving it in edit.js
export default function Edit({ attributes, setAttributes, clientId }) { const instanceId = clientId; useEffect(() => { setAttributes({ instanceId }); }, [instanceId]); ... }
and this is how id is in render.php
<div id="<?php echo $attributes['instanceId']; ?>"> </div>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to get the clientId from Edit.js to view.js in Dynamic Block’ is closed to new replies.