Angular Elements In React

What - Web Components

  • Custom Elements

  • Shadow DOM

  • HTML imports

  • HTML Template

What - Angular Elements

Angular elements are Angular components packaged as custom elements, a web standard for defining new HTML elements in a framework-agnostic way.

Why - Portability

  • Migrating Older projects
  • Organization-wide component library

Making A Basic WebComponent

Lifecycle Callbacks

  • connectedCallback => componentDidMount

  • disconnectedCallback => componentWillUnmount

  • attributeChangedCallback => componentDidUpdate

  • adoptedCallback => ¯\_(ツ)_/¯

https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#Using_the_lifecycle_callbacks

Using A Basic Web Component

Angular Elements (component)

Angular Elements (exporting)

Consuming a Web Component in React

Polyfill

Reactify

Demo Time

Caveats

  • Framework overhead (~60kb in this case)
  • Inelegant import process

Framework Overhead

~60kb in this case

Inelegant Import Process (Angular Specific)

Demo Time (The Code)

Thoughts

Citations and Further Reading

  • https://www.webcomponents.org/introduction

  • https://angular.io/guide/elements

  • https://github.com/webcomponents/react-integration

  • https://custom-elements-everywhere.com/

  • https://medium.com/@tomsu/building-web-components-with-angular-elements-746cd2a38d5b

Citations (contd): Images

  • http://www.thriveafterabuse.com/wp-content/uploads/2015/08/wolf-in-sheeps-clothing.jpg

Ready To Dive in Yourself