Skip to content

Commit

Permalink
fix: scroll up in parallel routes
Browse files Browse the repository at this point in the history
  • Loading branch information
sgomez committed Apr 28, 2024
1 parent a1d68b5 commit de1ad63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app/books/components/book-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Image from 'next/image'
import Link from 'next/link'

import { BookCardForm } from '@/app/books/components/book-card-form'
import { ScrollUp } from '@/components/scroll-up'
import { BookResponse } from '@/core/book/dto/responses/book.response'
import { UserResponse } from '@/core/user/dto/responses/user.response'

Expand Down Expand Up @@ -32,6 +33,7 @@ export function BookCard(properties: BookCardProperties) {

return (
<>
<ScrollUp />
<Card
as={Link}
className={`group max-w-[320px] space-y-4 border-t-4 p-4 ${cardColor}`}
Expand All @@ -40,7 +42,6 @@ export function BookCard(properties: BookCardProperties) {
prefetch
radius="none"
role="gridcell"
scroll={false}
>
<div className="relative">
<Image
Expand Down
9 changes: 9 additions & 0 deletions src/components/scroll-up.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

import { useEffect } from 'react'

export function ScrollUp() {
useEffect(() => window.document.scrollingElement?.scrollTo(0, 0), [])

return null
}

0 comments on commit de1ad63

Please sign in to comment.