Code cleaning
This commit is contained in:
+8
-5
@@ -23,15 +23,18 @@ const BookForm = () => {
|
||||
<input placeholder="author name" ...=${spread(authorProps)}>
|
||||
<button @click=${async () => {
|
||||
try {
|
||||
const data = await schema.validate({
|
||||
const newBook = await schema.validate({
|
||||
author: authorProps[".value"],
|
||||
title: titleProps[".value"]
|
||||
});
|
||||
|
||||
await addBook({ variables: data, update: (cache, result) => {
|
||||
const list: any = cache.readQuery({ query: GetBooks });
|
||||
cache.writeQuery({ query: GetBooks, data: { books: [...list.books, result.data.addBook] }});
|
||||
}});
|
||||
await addBook({
|
||||
variables: newBook,
|
||||
update: (cache, { data }) => {
|
||||
const { books }: any = cache.readQuery({ query: GetBooks });
|
||||
cache.writeQuery({ query: GetBooks, data: { books: [...books, data.addBook] }});
|
||||
}
|
||||
});
|
||||
|
||||
setTitle("");
|
||||
setAuthor("");
|
||||
|
||||
Reference in New Issue
Block a user