The term "reactive" applies to redrawing the UI/templates every time a reactive variable is modified.
Variables are not reactive within the JavaScript short of using an explicit setter; this is how JavaScript (and most languages) work; there has to be some sort of syntax to let the runtime know that the variable needs to be tracked for other functions to be called.
The wire method uses $
to signify that it should set up a setter for the variable to be reactive for the wire method.
This is actually similar to how Svelte uses reactive variables in JavaScript. In Svelte, for example, you can write:
$: totalTodos = todos.length;
Whenever todos
changes its length (via splice, push, pop, shift, unshift, or an assignment from slice, etc), Svelte automatically recalculates totalTodos
.
We don't have this feature in LWC, but the concept is similar to how @wire methods operate. We label the property with $
to tell the wire method that it should listen for changes to this property and perform some server call in response.
Without the $, the string is just a normal string, and if you just use this.variableName
, you only get one shot from the wire method (because it ends up looking like a string/number/whatever). We need this special symbol to make wire properties reactive.