Skip to content

Commit

Permalink
fix: hydration error
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbapapazes committed Jan 22, 2024
1 parent 222e893 commit f1fb82f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions composables/useBlog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function useBlog() {

const defaultQ: string = ''
const q = computed(() => {
return route.query.q as LocationQueryValue || defaultQ
})
return route.query.q as LocationQueryValue || defaultQ
})

const categoriesOptions = computed(() => {
const categories = data.value.flatMap(item => item.categories || [])
Expand All @@ -41,10 +41,10 @@ export function useBlog() {
})
const defaultCategories: string[] = []
const categories = computed(() => {
const categories = route.query['categories[]'] as LocationQueryValue[] || defaultCategories
const categories = route.query['categories[]'] as LocationQueryValue[] || defaultCategories

return (Array.isArray(categories) ? categories : [categories]) as string[]
})
return (Array.isArray(categories) ? categories : [categories]) as string[]
})

const packagesOptions = computed(() => {
const packages = data.value.flatMap(item => item.packages || [])
Expand All @@ -54,10 +54,10 @@ export function useBlog() {
})
const defaultPackages: string[] = []
const packages = computed(() => {
const packages = route.query['packages[]'] || defaultPackages
const packages = route.query['packages[]'] || defaultPackages

return (Array.isArray(packages) ? packages : [packages]) as string[]
})
return (Array.isArray(packages) ? packages : [packages]) as string[]
})

const authorsOptions = computed(() => {
const authors = data.value.flatMap(item => item.authors || [])
Expand All @@ -72,10 +72,10 @@ export function useBlog() {
})
const defaultAuthors: string[] = []
const authors = computed(() => {
const authors = route.query['authors[]'] || defaultAuthors
const authors = route.query['authors[]'] || defaultAuthors

return (Array.isArray(authors) ? authors : [authors]) as string[]
})
return (Array.isArray(authors) ? authors : [authors]) as string[]
})

const defaultOrder: Order = -1
const order = computed(() => {
Expand Down Expand Up @@ -110,7 +110,7 @@ export function useBlog() {
},
})

const articles = ref<BlogPostCard[]>(getArticles())
const articles = ref<BlogPostCard[]>()
const fetchBlogArticles = async () => {
if (data.value.length) {
miniSearch.addAll(data.value)
Expand Down Expand Up @@ -230,6 +230,8 @@ export function useBlog() {
})

onMounted(() => {
// Avoid hydration error when prerendering.
articles.value = getArticles()
// No query? Create one using stored data.
if (!hasQuery.value) {
navigateTo({
Expand Down

0 comments on commit f1fb82f

Please sign in to comment.