-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
2 - S (<= 1 week)
-
5471
-
Needed
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
Unable to find source-code formatter for language: tsx. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
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.
Unable to find source-code formatter for language: tsx. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
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