Skip to content

Commit

Permalink
Adds instance ID
Browse files Browse the repository at this point in the history
  • Loading branch information
kj committed Nov 18, 2023
1 parent ab560d9 commit 153a99c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/docs/md/elements/state/instance-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
title: Instance ID
---

`instanceID` is a unique identifier that is generated per Custom Element instance. This enables you to differentiate between multiple instances of the same element on a page. It can also be useful when using a string based diffing library like [Morphdom](https://github.com/patrick-steele-idem/morphdom) that require unique identifiers for DOM diffing.

```javascript
export default function MyCard({ html, state }) {
const { attrs={}, instanceID='' } = state
const { content='', heading='' } = attrs

return html`
<figure id="figure-${instanceID}">
<h2>${heading}</h2>
<p>${content}</p>
</figure>
`
}
```

0 comments on commit 153a99c

Please sign in to comment.