From c7ad69fff347afdca3410e4fb1da235be01b1ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Fri, 10 Jul 2020 10:04:54 +0200 Subject: [PATCH] fix: fix playground --- website/src/components/playground/Query.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/website/src/components/playground/Query.js b/website/src/components/playground/Query.js index ebe3334f..a3f090dd 100644 --- a/website/src/components/playground/Query.js +++ b/website/src/components/playground/Query.js @@ -12,7 +12,8 @@ function formatQuery(state, initialState) { }, {}, ) - return qs.stringify(lightState, { arrayFormat: 'bracket' }) + const qsStr = qs.stringify(lightState, { arrayFormat: 'bracket' }) + return qsStr ? `?${qsStr}` : '' } function parseQuery(query) { @@ -20,8 +21,9 @@ function parseQuery(query) { } function getLocation() { - if (typeof window === 'undefined') return { search: '', pathname: '' } - return window.location + if (typeof window === 'undefined') + return { location: { search: '', pathname: '' } } + return { location: window.location } } let browserHistory @@ -47,7 +49,7 @@ function useLocation() { export function useQuery(getInitialState = {}) { const history = useHistory() const [initialState] = React.useState(getInitialState) - const location = useLocation() + const { location } = useLocation() const locationRef = React.useRef(location) React.useEffect(() => { locationRef.current = location