# Function withLifecycle

- withLifecycle(tag, handler): CTag

- Will call {handler.onStart} when the element is added to the DOM. And will call {handler.onRemove} when the element is removed from the DOM.

  #### Parameters

  - ##### tag: CTag

  - ##### handler: {
    beforeRemove?: ((tag) => boolean | Promise<boolean>);
    removed?: ((tag) => void);
    start?: ((tag) => boolean | Promise<boolean>);
    }

    - ##### `Optional` beforeRemove?: ((tag) => boolean | Promise<boolean>)

      - - (tag): boolean | Promise<boolean>

        - #### Parameters

          - ##### tag: CTag

          #### Returns boolean | Promise<boolean>

    - ##### `Optional` removed?: ((tag) => void)

      - - (tag): void

        - #### Parameters

          - ##### tag: CTag

          #### Returns void

    - ##### `Optional` start?: ((tag) => boolean | Promise<boolean>)

      - - (tag): boolean | Promise<boolean>

        - #### Parameters

          - ##### tag: CTag

          #### Returns boolean | Promise<boolean>

  #### Returns CTag

  - Defined in lifecycle.ts:96

Generated using TypeDoc