Deriving Data
Deriving data is one of the key concepts with Reactivity, as it allows the UI to “settle” efficiently without the need to run extra computation cycles (or worse: re-renders).
In this lesson we’ll add secondary data to our counter that will double the value
First, in the HTML, we need to add a new element:
Then in our main.js
, we’ll need to query for that element:
and then we need to create another way to sync the data to the content of the doubledElement
.
Beneath our previous effect, we can add another
The derived data part here is the assignment:
This is possibly over-simplified, but the way we read this is that doubled
is the result of the computation on the right-hand side of the equals.
This will become important later, as we dive more in to deriving more complex data, and introduce class-based data derivation.
- Installing dependencies
- Starting http server