# Web components on Observable

**URL:** <https://talk.observablehq.com/t/web-components-on-observable/2561>\
**Category:** Help\
**Created:** [November 17, 2019, 9:22pm UTC](https://talk.observablehq.com/t/web-components-on-observable/2561 "2019-11-17T21:22:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rezpe](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/rezpe/32/1422_2.png) [@rezpe](https://talk.observablehq.com/u/rezpe)\
**Post date:** [November 17, 2019, 9:22pm UTC](https://talk.observablehq.com/t/web-components-on-observable/2561/1 "2019-11-17T21:22:09Z")

</div>

Hi,

I have not found any post on this, nor any example on the public notebooks. My question is how do we import web components on an observable notebook ? The standard implementation on a web page is to import the code in a js script, however that does not seem to be the way in observable. Hence my question ? For example, how it would be done for those components ?  
[https://lit-element-bootstrap.dev/getting-started](https://lit-element-bootstrap.dev/getting-started)

Thanks a lot,  
Sebas

---

<div class="post-metadata">

**Author:** ![j-f1](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/j-f1/32/368_2.png) [@j-f1](https://talk.observablehq.com/u/j-f1)\
**Post date:** [November 17, 2019, 11:29pm UTC](https://talk.observablehq.com/t/web-components-on-observable/2561/2 "2019-11-17T23:29:01Z")

</div>

Here’s a short demo:

> **[lit-elements Demo](https://observablehq.com/d/e7ef26d19516946e)**
>
> An Observable notebook by Jed Fox.

To import another component, go to `https://unpkg.com/@lit-element-bootstrap/[package name]?module` and copy the resulting URL after it redirects to the actual file name & version.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [November 17, 2019, 11:35pm UTC](https://talk.observablehq.com/t/web-components-on-observable/2561/3 "2019-11-17T23:35:04Z")

</div>

There’s another working example of Web Components here:

> **[Web component example with lit-element](https://observablehq.com/@jbouecke/web-component-example-with-lit-element)**
>
> An Observable notebook by jbouecke.

There are a couple of caveats, though.

The first is that Web Components doesn’t expose any way of removing or replacing a custom element definition. There’s [customElements.define](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define), and that’s it. That means that if you ever want to change your custom element definition, you have to reload the entire page. This goes against the grain of Observable, which uses dataflow to [re-evaluate cells automatically](https://observablehq.com/@observablehq/how-observable-runs).

The second is that Web Components cannot be statically analyzed. Consider this cell:

```auto
 html`<my-element mood="happy"></my-element>`

```

Observable has no way of knowing that the \<my-element\> custom element is defined by the cell called _MyElement_. And hence you could be creating those custom elements before the custom elements are defined. That might not be a problem—the browser will correct the display for custom elements that already exist in the DOM—but if you depend on certain runtime behavior in the cell that’s creating the elements, it might be surprising.

You can avoid the second caveat by making the dependency explicit by referencing the MyElement class, but it’s a little awkward:

```auto
MyElement, html`<my-element mood="happy"></my-element>`

```

---

<div class="post-metadata">

**Author:** ![rezpe](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/rezpe/32/1422_2.png) [@rezpe](https://talk.observablehq.com/u/rezpe)\
**Post date:** [November 18, 2019, 7:53am UTC](https://talk.observablehq.com/t/web-components-on-observable/2561/4 "2019-11-18T07:53:28Z")

</div>

Thanks both ! I do understand the problem. Does that mean that other approaches like Vue.js or React are preferred or more adapted to observable ?

---

<div class="post-metadata">

**Author:** ![j-f1](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/j-f1/32/368_2.png) [@j-f1](https://talk.observablehq.com/u/j-f1)\
**Post date:** [November 18, 2019, 1:57pm UTC](https://talk.observablehq.com/t/web-components-on-observable/2561/5 "2019-11-18T13:57:02Z")

</div>

Yep! Here’s a notebook for Vue:

> **[Using Vue with Observable](https://observablehq.com/@tmcw/using-vue-with-observable)**
>
> An Observable notebook by Tom MacWright.

And one for React:

> **[React](https://observablehq.com/@j-f1/react)**
>
> An Observable notebook by Jed Fox.

But most of the time you’ll be just fine with the native DOM APIs.
