See how Stencil fits into the entire Ionic Ecosystem ->
Stencil is part of the Ionic Ecosystem ->

Component API

The whole API provided by stencil can be condensed in a set of decorators, lifecycles hooks and rendering methods.

Decorators

Decorators are a pure compiler-time construction used by stencil to collect all the metadata about a component, the properties, attributes and methods it might expose, the events it might emit or even the associated stylesheets. Once all the metadata has been collected, all the decorators are removed from the output, so they don't incur in any runtime overhead.

  • @Component() declares a new web component
  • @Prop() declares an exposed property/attribute
  • @State() declares an internal state of the component
  • @Watch() declares a hook that runs when a property or state changes
  • @Element() declares a reference to the host element
  • @Method() declares an exposed public method
  • @Event() declares a DOM event the component might emit
  • @Listen() listens for DOM events

Lifecycle hooks

Other

  • Host: Host is a functional component that can be used at the root of the render function to set attributes and event listeners to the host element itself.

  • h(): It's used within the render() to turn the JSX into Virtual DOM elements.

  • readTask(): Schedules a DOM-read task. The provided callback will be executed in the best moment to perform DOM reads without causing layout thrashing.

  • writeTask(): Schedules a DOM-write task. The provided callback will be executed in the best moment to perform DOM mutations without causing layout thrashing.

  • forceUpdate(): Schedules a new render of the given instance or element even if no state changed. Notice forceUpdate() is not syncronous and might perform the DOM render in the next frame.

  • getAssetPath()

  • setMode()

  • getMode()

  • getElement()

BackNext
Contributors