After render method in a Widget

1047
4
07-09-2021 07:13 AM
MartijnHoogstraten
New Contributor II

Hello Esri community,

Is there a method or event in a widget that will be executed after rendering elements into the dom?

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Widget.html#render

 

Thank you

4 Replies
AndyGup
Esri Regular Contributor

Hi @MartijnHoogstraten the short answer is no. What are you trying to do? Here's the widget life cycle events: https://developers.arcgis.com/javascript/latest/custom-widget/#widget-life-cycle

MartijnHoogstraten
New Contributor II

Hi Andy, thanks for responding.

Sometimes we want to use node object to change states or use some of the DOM methods. But if we create a new widget inside a widget e.g. <div afterCreate={this.createSubWidget.bind(this)} /> and that subwidget for example sets something inside the attribute value of an input field. The input element has not been rendered yet, so what we do now is in the sub widget we do a afterCreate and set the node to a property inside the widget and we emit an event that the node has been set. We then use that event to do something with that node.

If there is an afterRender method im always sure that the node is available and we dont have to create custom events.

0 Kudos
AndyGup
Esri Regular Contributor

Interesting, I think I understand your issue that there is a chain of synchronous DOM events after the parent widget has been created, and the question is whether or not the parent is aware when the final afterCreate event takes place. I'm just wondering, have you look at setting afterUpdate on the parent div? I can see there being potential problems with that but just in case here's the doc: https://maquettejs.org/typedoc/interfaces/vnodeproperties.html#afterupdate. Also on that page you can browse through all the event methods. 

Reference: https://developers.arcgis.com/javascript/latest/custom-widget/#widget-rendering 

MartijnHoogstraten
New Contributor II

Thank you Andy.

After update will be triggered everytime something changes inside the node, in that case we get addional code to check wheater we already have set certain variables. But it is another solution. I think for now i understand the limitation and writing an event is not a big of a deal, lets hope we get more flexibility in the near future.

0 Kudos