Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Reactive function in svelte not firing when the value changes?

$
0
0

Entire code sample below.

The problem I have is that I know vatSuccess is actually changing successfully. However when I try to do anything with it in a reactive manner when I know it should be true it does not seem to work.

In the sample below I would expect the reactive statement console logging 'vatSuccess' to run twice first when it's declared as false and then again when it becomes true.

However it only runs the first time

let vatSuccess = falselet nameSuccess = falsefunction handleVatValidation(): Error {    // Vat is optional so putting nothing passes validation    if (companyInformation.vat.length === 0) {        vatSuccess = true        vatError = null        return null    }    if (companyInformation.vat.length < 6) {        vatSuccess = false        vatError = 'vat must be at least 6 characters'        return 'vat must be at least 6 characters'    }    vatSuccess = true    console.log('vatSuccess', vatSuccess) // This code runs and prints true    vatError = null    return null}$: {    console.log('vatSuccess', vatSuccess) // This only runs once when it is false}

I have tried to change it liek this so vatSuccess is a reactive value to begin with but the behaviour is the same.

$: vatSuccess = false

Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>