# decorateWidget does not return vDom element

**URL:** https://meta.discourse.org/t/decoratewidget-does-not-return-vdom-element/46680
**Category:** Development
**Created:** [June 30, 2016, 8:36pm UTC](https://meta.discourse.org/t/decoratewidget-does-not-return-vdom-element/46680 "2016-06-30T20:36:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)
#### Post date: [June 30, 2016, 8:36pm UTC](https://meta.discourse.org/t/decoratewidget-does-not-return-vdom-element/46680/1 "2016-06-30T20:36:29Z")

</div>

Continuing the discussion from [Accessing topic.views from widget or plugin initializer](https://meta.discourse.org/t/accessing-topic-views-from-widget-or-plugin-initializer/46642):

I was encountering issues, as per the linked topic and I have boiled it down to this:

I cannot seem to return a virtual-dom element to `api.decorateWidget` from within a function.

As an example, this works:

```
api.decorateWidget('post-meta-data:after', dec => {
  return h('i.fa.fa-eye')
});

```

But **this** do **not** work:

```
api.decorateWidget('post-meta-data:after', dec => {
  function doThis() {      
    return h('i.fa.fa-eye')
  }
  doThis();
});

```

Can’t figure out why?

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [June 30, 2016, 8:39pm UTC](https://meta.discourse.org/t/decoratewidget-does-not-return-vdom-element/46680/2 "2016-06-30T20:39:39Z")

</div>

Scope?

maybe

```plaintext
api.decorateWidget('post-meta-data:after', dec => {
  function doThis() {      
    return h('i.fa.fa-eye')
  };
  return doThis();
});

```

---

<div class="post-metadata">

### Author: ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)
#### Post date: [June 30, 2016, 8:44pm UTC](https://meta.discourse.org/t/decoratewidget-does-not-return-vdom-element/46680/3 "2016-06-30T20:44:16Z")

</div>

Oh wait ya I just realized that too. I should just use my actual code instead of trying to simplify my problem.

I am doing this:

```
api.decorateWidget('post-meta-data:after', dec => {
  const attrs = dec.attrs;
  function passViews(views) {
    //views is successfully passed to this function from getJSON
    console.log(views);
    //the below vDom test element does NOT attach as expected
    return h('i.fa.fa-eye'));
  }
  $.getJSON(attrs.topicUrl + '.json', function (data) {
    //passing function to success because ultimately I want to
    // get the topic views
    success: passViews(data.views);
  });
});

```
