Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment into a variable used as an event handler is not reactive. #3659

Closed
yoshikiohshima opened this issue Oct 4, 2019 · 1 comment
Closed

Comments

@yoshikiohshima
Copy link

Describe the bug
A stackoverflow question: [(https://stackoverflow.com/questions/58226319/assignment-into-a-variable-used-as-an-event-handler-is-not-reactive)] raises an issue of a variable used as an event handler does not update.

<script>
let count = 0;
let handler = () => {};

function update() {
    if (count >= 3) {handler = () => {count = 0;}}
    count++;
}
setInterval(update, 1000);
</script>

<h1 on:click={handler}>{count}</h1>

From code, handler and count both are props and the h1 element uses, but handler does not update the on:click action.

Note that this may just be a succinct example of #3040.

To Reproduce
Visit this REPL, wait three seconds and click the number:

https://svelte.dev/repl/cb0469ba5d8241e382677ad95a659b76?version=3.12.1

@Conduitry
Copy link
Member

Yeah I'd say this is a duplicate of #3040.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants