Skip to content

Instantly share code, notes, and snippets.

@ttristan
Created March 23, 2018 08:12
Show Gist options
  • Save ttristan/3c73fb31c977c99e862159c2fab2aa69 to your computer and use it in GitHub Desktop.
Save ttristan/3c73fb31c977c99e862159c2fab2aa69 to your computer and use it in GitHub Desktop.
import { push } from "react-router-redux";
import qs from "query-string";
export const updateRouter = ({ inputId, inputValue }) => {
return function(dispatch, getState) {
const currentSearch = qs.parse(getState().router.location.search);
const searchParams = { ...currentSearch, [inputId]: inputValue };
if (!inputValue || inputValue.length === 0 || inputValue === "false") delete searchParams[inputId];
const search = qs.stringify(searchParams);
const pathname = getState().router.location.pathname;
dispatch(
push({
pathname,
search
})
);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment