-
I get an error on lines 3 and 4. The error message is as follows Actually, this doesn't change even if |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You might need an effect here since the value is both editable and presumably should update when the route changes. Something like: const isDaily = $derived($page.route.id == '/daily');
let start = $state(startForRoute()); // can be left undefined if value is not needed right away
let end = $state(endForRoute());
$effect.pre(() => {
start = startForRoute();
end = endForRoute();
});
function startForRoute() {
// now probably needs to be reconstructed in these functions
return now
.subtract(1, 'month')
.format(isDaily ? 'YYYY-MM-DD' : 'YYYY-MM');
}
function endForRoute() {
return now.format(isDaily ? 'YYYY-MM-DD' : 'YYYY-MM');
} If you have additional dependencies, you may need |
Beta Was this translation helpful? Give feedback.
$state
initializes a new independent state, the warning tells you that the value will not update whenisDaily
is updated.You might need an effect here since the value is both editable and presumably should update when the route changes.
Something like: