Created
November 16, 2018 08:21
-
-
Save tomcask/db52e2b61f671751f9807bdcd81c80e7 to your computer and use it in GitHub Desktop.
returns an object reliable like as props of React components
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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