How to use the use-query-params.useQueryParam function in use-query-params

To help you get started, we’ve selected a few use-query-params examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hotosm / tasking-manager / frontend / src / views / taskAction.js View on Github external
export function TaskAction({ project, action }: Object) {
  const userDetails = useSelector(state => state.auth.get('userDetails'));
  const token = useSelector(state => state.auth.get('token'));
  // eslint-disable-next-line
  const [editor, setEditor] = useQueryParam('editor', StringParam);
  const [tasks, setTasks] = useState([]);
  const [loading, setLoading] = useState(true);
  useEffect(
    () => {
      if (userDetails.id && token && action) {
        fetchLocalJSONAPI(`users/${userDetails.id}/tasks/?status=LOCKED_FOR_${action}`, token).then(
          res => {
            console.log(res);
            setTasks(res.tasks);
            setLoading(false);
          }
        );
      }
    }, [action, userDetails.id, token]
  );
  if (token) {
github pbeshai / use-query-params / examples / website-example / src / UseQueryParamExample.tsx View on Github external
const UseQueryParamExample = () => {
  const [foo, setFoo] = useQueryParam('foo', StringParam);
  const [arr, setArr] = useQueryParam('arr', NumericArrayParam);

  // verify we aren't creating new arrays each time
  const prevArr = React.useRef(arr);
  React.useEffect(() => {
    if (prevArr.current !== arr) {
      console.log('new array. was:', prevArr.current, 'now:', arr);
    } else {
      console.log('same array');
    }
    prevArr.current = arr;
  });

  const nextFoo = nanoid(4);
  const nextArr = [
    Math.round(Math.random() * 100),
    Math.round(Math.random() * 100),
github pbeshai / use-query-params / examples / react-router / src / UseQueryParamExample.tsx View on Github external
const UseQueryParamExample = () => {
  const [count, setCount] = React.useState(0);
  const [zzz, setZzz] = useQueryParam('zzz', NumberParam);
  const [custom, setCustom] = useQueryParam('custom', MyParam);
  const [test, setTest] = useQueryParam('test', StringParam);
  const [anyp, setAnyP] = useQueryParam('anyp');
  const [arr, setArr] = useQueryParam('arr', ArrayParam);

  // verify we aren't creating new arrays each time
  const prevArr = React.useRef(arr);
  React.useEffect(() => {
    if (prevArr.current !== arr) {
      console.log('new array. was:', prevArr.current, 'now:', arr);
    } else {
      console.log('same array');
    }
    prevArr.current = arr;
  });
github alexieyizhe / intern.plus / src / shared / hooks / useSearchParams.ts View on Github external
const { searchSalaryFilter, setSearchSalaryFilter } = useMemo(
    () => ({
      searchSalaryFilter: salaryFilterStrArr
        ? salaryFilterStrArr.split(",").map(n => (n ? parseInt(n) : undefined))
        : undefined,
      setSearchSalaryFilter: (value?: (number | undefined)[]) =>
        setSalaryFilterStrArr(
          value && (value[0] || value[1])
            ? `${value[0] || ""},${value[1] || ""}`
            : undefined
        ),
    }),
    [salaryFilterStrArr, setSalaryFilterStrArr]
  );

  const [searchLocationFilter, setSearchLocationFilter] = useQueryParam(
    SearchParamKey.LOCATION_FILTER,
    ArrayParam
  );

  return {
    searchQuery,
    setSearchQuery,

    searchType: searchType as SearchType | undefined,
    setSearchType,

    searchSort: searchSort as SearchSort | undefined,
    setSearchSort,

    searchRatingFilter,
    setSearchRatingFilter,
github alexieyizhe / intern.plus / src / shared / hooks / useSearchParams.ts View on Github external
export const useSearchParams = () => {
  /**
   * Query parameter stores the value of the search query.
   */
  const [searchQuery, setSearchQuery] = useQueryParam(
    SearchParamKey.QUERY,
    StringParam
  );

  const [searchType, setSearchType] = useQueryParam(
    SearchParamKey.TYPE,
    StringParam
  );

  const [searchSort, setSearchSort] = useQueryParam(
    SearchParamKey.SORT,
    StringParam
  );

  const [ratingFilterStrArr, setRatingFilterStrArr] = useQueryParam(
    SearchParamKey.RATING_FILTER,
    StringParam
  );
  const { searchRatingFilter, setSearchRatingFilter } = useMemo(
    () => ({
      searchRatingFilter: ratingFilterStrArr
        ? ratingFilterStrArr.split(",").map(n => (n ? parseInt(n) : undefined))
        : undefined,
      setSearchRatingFilter: (value?: (number | undefined)[]) =>
        setRatingFilterStrArr(
          value && (value[0] || value[1])
github hotosm / tasking-manager / frontend / src / components / taskSelection / taskList.js View on Github external
export function TaskList({ project, tasks, activeFilter, selectTask, selected }: Object) {
  const user = useSelector(state => state.auth.get('userDetails'));
  const [readyTasks, setTasks] = useState([]);
  const [textSearch, setTextSearch] = useQueryParam('search', StringParam);
  const [sortBy, setSortingOption] = useQueryParam('sortBy', StringParam);
  const [statusFilter, setStatusFilter] = useQueryParam('filter', StringParam);

  useEffect(() => {
    if (tasks && tasks.activity) {
      let newTasks = tasks.activity;
      if (statusFilter === 'readyToMap') {
        newTasks = newTasks.filter(task => ['READY', 'INVALIDATED'].includes(task.taskStatus));
      }
      if (statusFilter === 'readyToValidate') {
        newTasks = newTasks.filter(task => ['MAPPED', 'BADIMAGERY'].includes(task.taskStatus));
      }
      if (textSearch) {
        newTasks = newTasks.filter(
          task =>
            task.taskId === Number(textSearch) ||
            (task.actionBy && task.actionBy.includes(textSearch)),
github mirumee / saleor-storefront / src / views / Collection / View.tsx View on Github external
export const View: React.FC = ({ match }) => {
  const [sort, setSort] = useQueryParam("sortBy", StringParam);
  const [attributeFilters, setAttributeFilters] = useQueryParam(
    "filters",
    FilterQuerySet
  );

  const clearFilters = () => {
    setAttributeFilters({});
  };

  const onFiltersChange = (name, value) => {
    if (attributeFilters && attributeFilters.hasOwnProperty(name)) {
      if (attributeFilters[name].includes(value)) {
        if (filters.attributes[`${name}`].length === 1) {
          const att = { ...attributeFilters };
          delete att[`${name}`];
          setAttributeFilters({
            ...att,
github alexieyizhe / intern.plus / src / shared / hooks / useSearchParams.ts View on Github external
export const useSearchParams = () => {
  /**
   * Query parameter stores the value of the search query.
   */
  const [searchQuery, setSearchQuery] = useQueryParam(
    SearchParamKey.QUERY,
    StringParam
  );

  const [searchType, setSearchType] = useQueryParam(
    SearchParamKey.TYPE,
    StringParam
  );

  const [searchSort, setSearchSort] = useQueryParam(
    SearchParamKey.SORT,
    StringParam
  );

  const [ratingFilterStrArr, setRatingFilterStrArr] = useQueryParam(
    SearchParamKey.RATING_FILTER,
    StringParam
  );
  const { searchRatingFilter, setSearchRatingFilter } = useMemo(
    () => ({
      searchRatingFilter: ratingFilterStrArr
github mirumee / saleor-storefront / src / views / Category / View.tsx View on Github external
export const View: React.FC = ({ match }) => {
  const [sort, setSort] = useQueryParam("sortBy", StringParam);
  const [attributeFilters, setAttributeFilters] = useQueryParam(
    "filters",
    FilterQuerySet
  );

  const clearFilters = () => {
    setAttributeFilters({});
  };

  const onFiltersChange = (name, value) => {
    if (attributeFilters && attributeFilters.hasOwnProperty(name)) {
      if (attributeFilters[name].includes(value)) {
        if (filters.attributes[`${name}`].length === 1) {
          const att = { ...attributeFilters };
          delete att[`${name}`];
          setAttributeFilters({
github mirumee / saleor-storefront / src / views / Category / View.tsx View on Github external
export const View: React.FC = ({ match }) => {
  const [sort, setSort] = useQueryParam("sortBy", StringParam);
  const [attributeFilters, setAttributeFilters] = useQueryParam(
    "filters",
    FilterQuerySet
  );

  const clearFilters = () => {
    setAttributeFilters({});
  };

  const onFiltersChange = (name, value) => {
    if (attributeFilters && attributeFilters.hasOwnProperty(name)) {
      if (attributeFilters[name].includes(value)) {
        if (filters.attributes[`${name}`].length === 1) {
          const att = { ...attributeFilters };
          delete att[`${name}`];
          setAttributeFilters({
            ...att,