Skip to content

Svelte 5 bug? #14463

Answered by brunnerh
dvlpr91 asked this question in Q&A
Discussion options

You must be logged in to vote

$state initializes a new independent state, the warning tells you that the value will not update when isDaily is updated.

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');
}

fun…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dvlpr91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants