Skip to content

Instantly share code, notes, and snippets.

@tomcask
Created November 16, 2018 08:21
Show Gist options
  • Save tomcask/db52e2b61f671751f9807bdcd81c80e7 to your computer and use it in GitHub Desktop.
Save tomcask/db52e2b61f671751f9807bdcd81c80e7 to your computer and use it in GitHub Desktop.
returns an object reliable like as props of React components
const convertQueryParamsToProps = query =>
query.split("&")
.map(item => item.split("="))
.reduce((params, queryParam) =>
(params[queryParam[0]]= queryParam[1]) && params
, {})
}
convertQueryParamsToProps("tomas=mola&foo=1")
//{tomas: "mola", foo: "1"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment