I'm developing a custom plugin with react and I would like to create a unique identifier for each new added instance of my custom block as soon as it is added to the page.
So I add my "custom block" and the code runs once to create and assign the id. When I visit the backend again, the code should not run again. But if I add a new instance of my "custom block", the code runs once again for this instance and creates & assigns a new id. So I guess I'm looking for a hook like "blockAddedToPage" or so, but I can't find something matching.
I know that there is the clientid, but I need something permanent and shorter :D
I wrote a small helper function to create my id, but how do I run it only when the block is added to the page?
useEffect
, but there are times when that is definitely not the solution. So is watching the data store, filters, and it may be that you're headed down a dead end, a lot of people who ask this are trying to do something they shouldn't that leads to lots of new problems. Give us some context for what you're trying to do to make the question answerable, and eliminate possibilities