SWRで爆死を避ける。firebase Cloud FirestoreとNext.js。
BRANK

はじめに2か月前に「SWRを使おうぜという話」という記事を書きました。 Categories = 'ブログ' 'ニュース'; type Post = { slug: string; title: string; category: Categories; body: string; createdAt: string; updatedAt: string; } const validate = (data: any): data is Post => { if (!(data.slug typeof data.slug === 'string')) { return false; } if (!(data.title typeof data.title === 'string')) { return false; } const cat: Categories[] = ['ブログ', 'ニュース']; if (!(data.category cat.some((c) => data.category === c))) { return false; } if (!(data.body typeof data.body === 'string')) { return false; } return true; }; const toFirestore = (post: Post): DocumentData => { return { slug: post.slug, title: post.title, category: post.category, body: post.body, createdAt: post.createdAt, updatedAt: post.updatedAt }; }; const fromFirestore = ( snampshot: QueryDocumentSnapshot, …

zenn.dev
Related Topics: X as a Service Google Cloud Platform React