Skip to content

Commit

Permalink
Merge pull request #46 from dadoagency/martink-rsa/useRedirectDestina…
Browse files Browse the repository at this point in the history
…tion-hook-changes

Added a return to the redirect hook
  • Loading branch information
Geimaj committed Nov 9, 2020
2 parents 14ecfa5 + 81efe09 commit 49aeb4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/context/PageContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const PageContext = React.createContext(defaultState)

const PageProvider = ({ children }) => {
const [redirectDestination, setRedirectDestination] = useState("")

return (
<PageContext.Provider
value={{
Expand Down
8 changes: 6 additions & 2 deletions src/hooks/useRedirectDestination.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useEffect, useContext } from "react"
import { useState, useEffect, useContext } from "react"
import PageContext from "../context/PageContext"
import { getRedirectDestination, getQueryParam } from "../utils/splitRedirect"

const useRedirectDestination = candidates => {
const { setRedirectDestination } = useContext(PageContext)
const { redirectDestination, setRedirectDestination } = useContext(PageContext)
const [params, setParams] = useState(null)

useEffect(() => {
if (candidates && candidates.length > 0) {
Expand All @@ -13,10 +14,13 @@ const useRedirectDestination = candidates => {
let queryString = ""
queryString = getQueryParam(params)
window.history.replaceState(null, null, queryString)
setParams(params)
setRedirectDestination(url + queryString)
}
}
}, [setRedirectDestination, candidates])

return { url: redirectDestination, params}
}

export default useRedirectDestination

0 comments on commit 49aeb4a

Please sign in to comment.