mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
[diff facebook/[email protected]](https://github.com/facebook/react/compare/fef12a01...da9325b5) <details> <summary>React upstream changes</summary> - https://github.com/facebook/react/pull/35962 - https://github.com/facebook/react/pull/35961 - https://github.com/facebook/react/pull/36277 - https://github.com/facebook/react/pull/36297 - https://github.com/facebook/react/pull/36292 - https://github.com/facebook/react/pull/36291 - https://github.com/facebook/react/pull/36196 - https://github.com/facebook/react/pull/36246 - https://github.com/facebook/react/pull/36287 - https://github.com/facebook/react/pull/36285 - https://github.com/facebook/react/pull/36274 - https://github.com/facebook/react/pull/36266 - https://github.com/facebook/react/pull/36253 </details>
38 lines
971 B
JavaScript
38 lines
971 B
JavaScript
'use client'
|
|
import { useRouter } from 'next/navigation'
|
|
import { useState } from 'react'
|
|
|
|
export function NavigateAndTrackRouterIdentity({ href }) {
|
|
const router = useRouter()
|
|
const [prevRouter, setPrevRouter] = useState(router)
|
|
|
|
const [changedCount, setChangedCount] = useState(0)
|
|
if (prevRouter !== router) {
|
|
setPrevRouter(router)
|
|
setChangedCount((p) => p + 1)
|
|
}
|
|
|
|
const [navigationCount, setNavigationCount] = useState(0)
|
|
const navigate = () => {
|
|
setNavigationCount((p) => p + 1)
|
|
console.log('navigating to', href)
|
|
router.push(href)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div>
|
|
navigations (without unmounting this component):{' '}
|
|
<span id="count-from-client-state">{navigationCount}</span>
|
|
</div>
|
|
<div>
|
|
router identity changes:{' '}
|
|
<span id="router-change-count">{changedCount}</span>
|
|
</div>
|
|
<button id="trigger-push" onClick={navigate}>
|
|
navigate
|
|
</button>
|
|
</>
|
|
)
|
|
}
|