jmurzy / jmurzy/react-router-native

Please sanity test my query modification functions [Suggestion?]

Open
#76 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
639
Forks
38
PR merge metrics
No merged PRs in 30d

Description

Hi,

I threw together some quick & dirty helper functions for modifying the "query string".

I'm not very familiar with this project, and I was wondering:

**Question**: Is the following approach is (broadly) aligned with the intended usage of this project?

```js
import qs from 'query-string';

/**
* Warning: I don't know if anything relies on query-string format,
* but I will keep for convention
*/

export const removeQuery = (prevLocation = {}, history, ...queryKeys) => {
const location = Object.assign({}, prevLocation);
const searchObj = qs.parse(location.search);
queryKeys.forEach(q => delete searchObj[q]);
location.search = qs.stringify(searchObj);
history.push(location);
};

export const addQuery = (prevLocation = {}, history, queryObj) => {
const location = Object.assign({}, prevLocation);
const searchObj = Object.assign(
qs.parse(location.search),
queryObj
);
location.search = qs.stringify(searchObj);
history.push(location);
};

export const getQuery = (prevLocation = {}, queryKey) => {
const searchObj = qs.parse(prevLocation.search);
return searchObj[queryKey];
};

```

Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.