Skip to content

Element event directives reactivity #4388

Closed
@oreilles

Description

@oreilles

I'm in a context similar to the one below:

Some DOM element (here a button), which when clicked should call a callback function (test), which may change depending on a certain state (the variable bool)

let bool = false
	
let foo = () => console.log("foo")
let bar = () => console.log("bar")

$: test = bool ? foo : bar;

When the variable bool change, the callback is only updated when writing the directive like this:

<button on:click={() => test()} />

But if written that way, the callback will keep its first value even if the state change:

<button on:click={test} />

I would expect the two declarations to behave in the same way.

Replicate:
https://svelte.dev/repl/ca0fbda83f654f5a8829282a59f511f1?version=3.18.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions