You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
553 B
23 lines
553 B
import { useMemo } from 'react'
|
|
import { useLocation } from 'react-router'
|
|
|
|
import isNumber from 'lodash/isNumber'
|
|
|
|
export const RESUME_KEY = 'resume'
|
|
|
|
const readResumeParam = (search: string) => {
|
|
const params = new URLSearchParams(search)
|
|
const rawValue = params.get(RESUME_KEY)
|
|
if (!rawValue) return undefined
|
|
|
|
const value = JSON.parse(rawValue)
|
|
return isNumber(value) ? value : 0
|
|
}
|
|
|
|
export const useUrlParam = () => {
|
|
const { search } = useLocation()
|
|
|
|
const resume = useMemo(() => readResumeParam(search), [search])
|
|
|
|
return resume
|
|
}
|
|
|