# Callback with arguments

**URL:** <https://forums.fusetools.com/t/callback-with-arguments/1806>\
**Category:** How-to Discussions\
**Created:** [December 28, 2015, 12:12pm UTC](https://forums.fusetools.com/t/callback-with-arguments/1806 "2015-12-28T12:12:51Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![klayer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/klayer/32/505_2.png) [@klayer](https://forums.fusetools.com/u/klayer)\
**Post date:** [December 28, 2015, 12:12pm UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/1 "2015-12-28T12:12:51Z")

</div>

Hi,

I wonder why the `Callback` doesn’t accept arguments like:

```auto
<Rectangle>
    <Clicked>
        <Callback Handler="{click}">
            <Argument>arg1</Argument>
            <Argument>arg2</Argument>
        </Callback>
    </Clicked>
</Rectangle>

```

It is cheap to use callbacks with arguments, otherwise I export many functions with different arguments.

Or, is there another better solution? I know the callback function binding with a data context object, but this doesn’t help much.

Thanks!

---

<div class="post-metadata">

**Author:** ![Vegard\_Strand\_Lende](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/vegard_strand_lende/32/349_2.png) [@Vegard\_Strand\_Lende](https://forums.fusetools.com/u/Vegard_Strand_Lende)\
**Post date:** [January 5, 2016, 12:00pm UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/2 "2016-01-05T12:00:49Z")

</div>

Hi!

Thanks for reporting, you raise a good point. There is not a better solution than exposing the appropriate functions and obeservables. What usecase are you trying to solve here?

If we can find a proper usecase for this kind of logic we can add a feature request 🙂

---

<div class="post-metadata">

**Author:** ![Bjorn-Olav\_Strand](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/bjorn-olav_strand/32/583_2.png) [@Bjorn-Olav\_Strand](https://forums.fusetools.com/u/Bjorn-Olav_Strand)\
**Post date:** [January 6, 2016, 10:59am UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/3 "2016-01-06T10:59:59Z")

</div>

Just to hi-jack this thread. The reason I want something like this is to not have a lot of wrapper functions.

I don’t like this so much:

```auto
<Button><Callback Handler"{setTitleToText1}" /></Button>
<Button><Callback Handler"{setTitleToText2}" /></Button>
<Button><Callback Handler"{setTitleToText3}" /></Button>
<Button><Callback Handler"{setTitleToText4}" /></Button>
<Button><Callback Handler"{setTitleToText5}" /></Button>
<Button><Callback Handler"{setTitleToText6}" /></Button>
<Button><Callback Handler"{setTitleToText7}" /></Button>

```

---

<div class="post-metadata">

**Author:** ![Sven\_Wiese-Solty](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/sven_wiese-solty/32/325_2.png) [@Sven\_Wiese-Solty](https://forums.fusetools.com/u/Sven_Wiese-Solty)\
**Post date:** [January 7, 2016, 7:24pm UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/4 "2016-01-07T19:24:34Z")

</div>

I also would like to do something like this to centralize handlers or to use callbacks in enums.

---

<div class="post-metadata">

**Author:** ![Mitnick](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mitnick](https://forums.fusetools.com/u/Mitnick)\
**Post date:** [August 12, 2016, 5:41pm UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/5 "2016-08-12T17:41:30Z")

</div>

Any updates? Can we now pass arguments?

---

<div class="post-metadata">

**Author:** ![Jake\_Taylor](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/jake_taylor/32/512_2.png) [@Jake\_Taylor](https://forums.fusetools.com/u/Jake_Taylor)\
**Post date:** [August 16, 2016, 2:54pm UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/6 "2016-08-16T14:54:42Z")

</div>

A `Button`'s (or `Panel`'s more generally) `Clicked` function will receive an object whose `data` field contains the data context for the `Button`, if that’s what you guys are after:

JS:

```auto
function handler(arg) {
    // arg.data represents the item that was the data context for the button below
}

```

UX:

```auto
<Each Items="{items}">
    <Button Clicked="{handler}" />
</Each>

```

---

<div class="post-metadata">

**Author:** ![Gabson](https://avatars.discourse-cdn.com/v4/letter/g/a6a055/32.png) [@Gabson](https://forums.fusetools.com/u/Gabson)\
**Post date:** [July 2, 2017, 1:08pm UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/7 "2017-07-02T13:08:48Z")

</div>

Hello!

I understand this example and use it in my app. But I am facing a problem I don’t understand.

arg.data contains my object, but when I try to use it it’s undefined: like this :

```auto
function addtobucket(arg) {

	dataStore.paniers.add(
		{
			name: "arg.data.name", // a test 
			id: arg.data._id, // undefined
			price: arg.data.price, // undefined
		}
	);
console.log("panier contient en JSON --> " + JSON.stringify(arg.data)); // when I try this I can see all the data is here

```

---

<div class="post-metadata">

**Author:** ![Jake\_Taylor](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/jake_taylor/32/512_2.png) [@Jake\_Taylor](https://forums.fusetools.com/u/Jake_Taylor)\
**Post date:** [July 3, 2017, 10:03am UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/8 "2017-07-03T10:03:23Z")

</div>

Hi Gabson, can you provide a complete, minimal, runnable example for me, so I can more easily run this myself and help you out? Thanks!

---

<div class="post-metadata">

**Author:** ![Gabson](https://avatars.discourse-cdn.com/v4/letter/g/a6a055/32.png) [@Gabson](https://forums.fusetools.com/u/Gabson)\
**Post date:** [July 3, 2017, 10:29am UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/9 "2017-07-03T10:29:00Z")

</div>

Hello Jake,

Thansk for your answer, I am discussing this issue with Uldis on slack.  
Great team by the way!

---

<div class="post-metadata">

**Author:** ![Jake\_Taylor](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/jake_taylor/32/512_2.png) [@Jake\_Taylor](https://forums.fusetools.com/u/Jake_Taylor)\
**Post date:** [July 3, 2017, 10:32am UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/10 "2017-07-03T10:32:27Z")

</div>

Cool, happy to hear it 😃

---

<div class="post-metadata">

**Author:** ![Kwame](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@Kwame](https://forums.fusetools.com/u/Kwame)\
**Post date:** [December 21, 2017, 6:50pm UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/11 "2017-12-21T18:50:08Z")

</div>

bumping this thread, was there an update on this? I have run into a similar issue and am interested to know.

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [December 22, 2017, 10:50am UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/12 "2017-12-22T10:50:37Z")

</div>

@Kwame: there are no updates on whatever was discussed here in particular. You should make a new forum post, explaining exactly what it is that you want to do, and we’ll likely figure out a way for you to do it.

---

<div class="post-metadata">

**Author:** ![Aditya\_Choudhary](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Aditya\_Choudhary](https://forums.fusetools.com/u/Aditya_Choudhary)\
**Post date:** [January 25, 2018, 4:19am UTC](https://forums.fusetools.com/t/callback-with-arguments/1806/13 "2018-01-25T04:19:10Z")

</div>

##### UserEvent will help you. (It accepts arguments)

&nbsp;

[https://www.fusetools.com/docs/fuse/userevent](https://www.fusetools.com/docs/fuse/userevent)

&nbsp;

Thanks to Fuse Devs for introducing this.
