Skip to content

Component lifecycle

Filatov Dmitry edited this page Feb 18, 2018 · 32 revisions

Component's lifecycle is represented via various hooks called by Vidom at specific points.

onInit

void onInit()

The callback will be invoked once after a component instance has been created. It's the best place to set initial state via setState.

onRender

VNode onRender()

The callback will be invoked when a component should be rendered. It's an essential part of the component lifecycle. It should return a single child node (with any type) based on this.attrs, this.children and possible internal state this.state of a component. This method is supposed to be pure, it should have no side effects. It's allowed to return null value, in this case nothing will be rendered.

onMount

void onMount()

The callback will be invoked once after a component has been rendered first time and mounted to the DOM.

onChange

void onChange(
    Object prevAttrs,
    Any prevChildren,
    Object prevState,
    Object prevContext
)

The callback will be invoked each time when component is changed (from parent or via setState) and component is going to perform rerender.

shouldRerender

Boolean shouldRerender(
    Object prevAttrs,
    Any prevChildren,
    Object prevState,
    Object prevContext
)

The callback will be invoked each time before a component is going to perform rerender. If it returns false a component won't be updated and rerendered.

onUpdate

void onUpdate(
    Object prevAttrs,
    Any prevChildren,
    Object prevState,
    Object prevContext
)

The callback will be invoked each time after a component has updated. It won't be called after an initial rendering and it will be called regardless result of shouldRerender.

onChildContextRequest

Object onChildContextRequest()

The callback will be invoked each time before a component is going to pass its context to children.

onUnmount

void onUnmount()

The callback will be invoked once before a component is unmounted from the DOM.