Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
NaridaL committed Jul 15, 2023
1 parent 11377cd commit a035959
Show file tree
Hide file tree
Showing 17 changed files with 1,334 additions and 1,059 deletions.
6 changes: 4 additions & 2 deletions src/common/useHashState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export function useHashState<S extends {}>(
const mergedState = deserialize(
Object.assign(serialize(state), parseHash(document.location.hash)),
) as S
history.pushState(
console.log("replaceState")
history.replaceState(
undefined,
document.title,
objectToHash(serialize(mergedState)),
Expand All @@ -96,7 +97,9 @@ export function useHashState<S extends {}>(
}, [deserialize, initialState, serialize])
const [state, setState] = useState<S>(createInitialState)
const updateHashRef = useRef<(newState: S) => void>()
useEffect(() => updateHashRef.current?.(state), [state])
if (!updateHashRef.current) {
console.log("pushState")
updateHashRef.current = debounce(function (newState: S) {
history.pushState(
undefined,
Expand All @@ -105,7 +108,6 @@ export function useHashState<S extends {}>(
)
}, wait)
}
useEffect(() => updateHashRef.current!(state), [state])

useEffect(() => {
const onHashChange: (e: HashChangeEvent) => void = () => {
Expand Down
Loading

0 comments on commit a035959

Please sign in to comment.