Hyperapp V2 lifecycle method (onCreate)

340 views Asked by At

How does lifecycle methods work in hyperapp v2? Why don't I see 'hello' in my console?

import { h, app } from "hyperapp";

app({
    init: { name: 'world' },
    view: ({ name }) => h('div', {
        onCreate: () => console.log('hello')
    }, `hello ${name}!!!`),
    node: document.getElementById("app")
});
1

There are 1 answers

4
Zach On

Lifecycle events are no longer a feature of hyperapp, as of v2, sorry. There was a lot of debate over this in the community, and they were not discarded lightly. But discarded they were.

It is possible to add them back yourself (by overriding the appendChild et c methods either in the vdom or on the Element.prototype) - but before trying that route, consider what you need them for. Most cases people were using lifecycle events for, there have been more robust solutions proposed by the community.