Skip to content

How to pass $derived or $state variable into a function parameter... #13080

Answered by 7nik
gio-hernandez-saito asked this question in Q&A
Discussion options

You must be logged in to vote

There are a few ways to keep reactivity while passing a value somewhere:

  1. Pass an object with all the data, but you should never replace or create it because the reactivity is bound to that object instance;
  2. Pass a getter () => someValue and then call it to get a fresh reactive value;
  3. Object with getters and optionally setters:
useAPIState({
  key: 'login',
  get data() { return params; },
});

and reading apiParams.data will always return a fresh data.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gio-hernandez-saito
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