Skip to content

[BUG] useTable setFilters issue when used with react-router useSearchParams hook. #7084

@ahmedmelfay

Description

@ahmedmelfay

Describe the bug

When using setFilters from the useTable hook, it removes any custom search query previously set using the useSearchParams from react-router library

export const MyComponent: React.FC = () => {
  const { setFilters } = useTable();
  const [, setSearchParams] = useSearchParams();

  return (
    <Button
      onClick={() => {
        setFilters([{ field: "customField", operator: "eq", value: "customValue" }]);
        const currentUrlParams = new URLSearchParams(window.location.search);
        currentUrlParams.set("customQueryKey", "customQueryValue");
        setSearchParams(currentUrlParams);
      }}
    >
      Click me
    </Button>
  );
};

Steps To Reproduce

  • Add new button component with onClick event

  • Inside onClick try to set the filters from useTable hook and try to set custom key/value in URL params using useSearchParams hook from react-router

Expected behavior

The custom query should be combined with the table filters / sorters

Packages

System:

  • OS: Windows 10 10.0.19045
  • CPU: (8) x64 Intel(R) Core(TM) i7-9700F CPU @ 3.00GHz

Binaries:

  • Node: 22.19.0 - C:\Program Files\nodejs\node.EXE
  • Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
  • npm: 10.9.3 - C:\Program Files\nodejs\npm.CMD

Browsers:

  • Chrome: 141.0.7390.108

Refine Packages:

  • @refinedev/antd: 6.0.2
  • @refinedev/cli: 2.16.49
  • @refinedev/core: 5.0.4
  • @refinedev/react-router: 2.0.1
  • @refinedev/simple-rest: 6.0.0

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions