2
\$\begingroup\$

Hi I using Vue 3 with Typescript. In my code I have variable:

const editItem = ref<{
  id: number
  title: string
  author: string
}>({
  id: 0,
  title: '',
  author: '',
})

This variable I update using this method:

const updateItem = (data: {
  id: number
  title: string
  author: string
}) => {
  const { title, author } = data

  getBooks.value = getBooks.value.map(book => ({
    ...book,
    title: editItem.value.id === book.id ? title : book.title,
    author: editItem.value.id === book.id ? author : book.author,
  }))
}

Did this code is correctly by typescript? I readed that I should using reactive instead of ref to object, but reactive value can not be empty

\$\endgroup\$
1
  • \$\begingroup\$ What is getBooks? Does the code work as you expect it to do? \$\endgroup\$ Commented Nov 1, 2020 at 12:21

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.