fix error page checkout
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { AnimatePresence, motion } from 'framer-motion'
|
import { AnimatePresence, motion } from 'framer-motion'
|
||||||
import { usePathname } from 'next/navigation'
|
import { usePathname } from 'next/navigation'
|
||||||
import React from 'react'
|
import React, { useRef } from 'react'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
@@ -12,15 +12,28 @@ type Props = {
|
|||||||
|
|
||||||
function ClientSideWrapper({ children, className = 'h-full' }: Props) {
|
function ClientSideWrapper({ children, className = 'h-full' }: Props) {
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
const isFirstMount = useRef(true)
|
||||||
|
const prevPathname = useRef(pathname)
|
||||||
|
|
||||||
|
// تشخیص اولین mount
|
||||||
|
const isInitial = isFirstMount.current
|
||||||
|
if (isFirstMount.current) {
|
||||||
|
isFirstMount.current = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// تشخیص تغییر pathname
|
||||||
|
const pathnameChanged = prevPathname.current !== pathname
|
||||||
|
prevPathname.current = pathname
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatePresence mode="wait">
|
<AnimatePresence mode="sync">
|
||||||
<motion.div
|
<motion.div
|
||||||
key={pathname}
|
key={pathname}
|
||||||
initial={{ opacity: 0, y: -10, }}
|
initial={isInitial || !pathnameChanged ? false : { y: -10 }}
|
||||||
animate={{ opacity: 1, y: 0 }}
|
animate={{ y: 0 }}
|
||||||
exit={{ opacity: 0, y: 0, transition: { duration: 0 } }}
|
exit={{ y: 0, transition: { duration: 0 } }}
|
||||||
transition={{ duration: 0.3 }}
|
transition={{ duration: 0.3 }}
|
||||||
|
style={{ opacity: 1 }}
|
||||||
className={clsx(className)}
|
className={clsx(className)}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
Reference in New Issue
Block a user