Please sanity test my query modification functions [Suggestion?]

Open
#76 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
javascript, react-native
Domain
mobile

Research direction

No repository files or tests are named. Start by reviewing the existing routing and location-query APIs, then compare the proposed addQuery, removeQuery, and getQuery helpers with the project's intended usage. Done would require a maintainer decision on whether this approach fits and what, if anything, should be added.

Written by the indexing model from the issue text.

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?

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

Dominant language
JavaScript
Stars
636
Forks
37
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jmurzy/react-router-native

All issues in jmurzy/react-router-native

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.