Skip to content

Commit

Permalink
remove old cleanup effect
Browse files Browse the repository at this point in the history
  • Loading branch information
oatkiller committed Aug 13, 2020
1 parent 7f1f453 commit b7258ed
Showing 1 changed file with 1 addition and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { useCallback, useMemo, useEffect } from 'react';
import { useCallback, useMemo } from 'react';
import { useHistory, useLocation } from 'react-router-dom';
import { useQueryStringKeys } from './use_query_string_keys';
import * as selectors from '../store/selectors';
import { CrumbInfo } from './panels/panel_content_utilities';

export function useResolverQueryParams() {
Expand Down Expand Up @@ -49,33 +48,6 @@ export function useResolverQueryParams() {
};
}, [urlSearch, idKey, eventKey]);

useEffect(() => {
/**
* Keep track of the old query string keys so we can remove them.
*/
const oldIdKey = idKey;
const oldEventKey = eventKey;
/**
* When `idKey` or `eventKey` changes (such as when the `resolverComponentInstanceID` has changed) or when the component unmounts, remove any state from the query string.
*/
return () => {
/**
* This effect must not be invalidated when `search` changes.
* Use the current location.search via the `history` object.
* `history` doesn't change so this is effectively like accessing `search` via a ref.
*/
const urlSearchParams = new URLSearchParams(history.location.search);

/**
* Remove old keys from the url
*/
urlSearchParams.delete(oldIdKey);
urlSearchParams.delete(oldEventKey);
const relativeURL = { search: urlSearchParams.toString() };
history.replace(relativeURL);
};
}, [idKey, eventKey, history]);

return {
pushToQueryParams,
queryParams,
Expand Down

0 comments on commit b7258ed

Please sign in to comment.