TagHook
This hook abstraction simplifies a Tag creating Hook by offering static invoke methods, which already deal with constructing the value field, so that an abstract renderTag method is called. This covers the typical use case where a client only wants to configure exactly one value (flow or static) and the hook should use this to render some artifact.
A good example would be a hook for rendering some icon; it would accept a special `IconDefinition`
and render some `<svg>`
-tag including sub-tags:
class IconHook : TagHook<Svg, Null, IconDefinition>() {
override fun RenderContext.renderTag(classes: String?, id: String?, data: IconDefinition, payload: Unit): Svg {
svg(classes, id) {
// set some attributes based upon the fields of imaginary ``IconDefinition``
}
}
}
Content copied to clipboard
So the client can easily call this:
// a component exposes this hook:
class SomeComponent {
val closeIcon = IconHook()
}
// Client configures this easily:
closeIcon(Icons.close)
Content copied to clipboard
Its main motivation is to reduce the repeating boilerplate code of exactly the same invoke method implementations.