Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argument to useQuery to allow result to be filtered and sorted #5471

Closed
takameyer opened this issue Feb 21, 2023 · 0 comments · Fixed by #5465 or #5513
Closed

Add argument to useQuery to allow result to be filtered and sorted #5471

takameyer opened this issue Feb 21, 2023 · 0 comments · Fixed by #5465 or #5513
Assignees

Comments

@takameyer
Copy link
Contributor

takameyer commented Feb 21, 2023

Problem

Currently when using useQuery, the result must be passed into a useMemo in order to get a memoized filtered or sorted result. This is also not particularly useful, as when the result of useQuery is re-rendered, the memo is called again as well as any filtered or sorted method calls.

For example

  const user = useUser();
  const userId = user.id;
  const result = useQuery(Task);

  const tasks = useMemo(() => result.filtered(“ownerId == $0”, userId).sorted('createdAt'), [result, userId]);

Solution

A more elegant solution would be to have a callback within useQuery which would allow the filtered and sorted functions to be applied within useQuery itself. It could also take a dependency array to determine when to reset the filtered or sorted method calls.

 const tasks = useQuery("Task", (tasks) => {
   return tasks.filtered(“ownerId == $0”, userId);
 }, [userId]);

Alternatives

No response

How important is this improvement for you?

Would be a major improvement

Feature would mainly be used with

Local Database only

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
1 participant