WoJ
WoJ

Reputation: 30054

How to "simulate" a Ref?

I have a Vue3 component in which setup() I defined the following function:

const writeNote(note: Ref<Note>) => { console.log(`note ${note.id}` }

It receives a Ref<Note>, and Note is an Interface.

This function is called on two occasions:

How can I solve this contradiction?

Upvotes: 0

Views: 57

Answers (1)

Bruno Francisco
Bruno Francisco

Reputation: 4240

You can use Vue's unref:

const writeNote(_note: Ref<Note> | Note) => { 
  const note = unref(_note);

  console.log(`note ${note.id}`);
}

Either that or you will have to create a reactive variable when passing to writeNote as you have described in your question. This solution is a bit cleaner but requires you to change writeNote's signature and inners of the function

Upvotes: 1

Related Questions