Hyperapp: Updating the state inside an element's oncreate event fails.

Created on 26 May 2017  路  4Comments  路  Source: jorgebucaran/hyperapp

When the oncreate event is fired for an element, it gets passed a reference to the actual DOM element. At this point in time, the element has been created using document.createElement or document.createTextNode, but it's still not appended to the DOM (because we haven't had time to call patch yet!).

When you call an action that updates the state, we'll try to render the app ahead of time, we'll have a new node, but not an old one, which will cause an exception.

See also: https://github.com/hyperapp/hyperapp/issues/208#issuecomment-304130612

Bug

Most helpful comment

@dodekeract Good news! We were able to fix this by introducing a new oninsert lifecycle event.

Fired after an element is created and inserted into the DOM. Use this event to wrap third party libraries that require a reference to a DOM node, etc.

All 4 comments

@dodekeract Good news! We were able to fix this by introducing a new oninsert lifecycle event.

Fired after an element is created and inserted into the DOM. Use this event to wrap third party libraries that require a reference to a DOM node, etc.

@jbucaran Hmm, I still think it's very odd that hyper app crashes when I do something with the state in the oncreate hook.

@dodekeract I think calling actions that update the state inside oncreate won't crash after #286 since rendering is now effectively async.

@dodekeract Having said that, "for the record", you shouldn't probably be calling actions inside oncreate, that's not what it exists for. 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jorgebucaran picture jorgebucaran  路  4Comments

jamen picture jamen  路  4Comments

guy-kdm picture guy-kdm  路  4Comments

jacobtipp picture jacobtipp  路  3Comments

icylace picture icylace  路  3Comments