@powersync/react 0.0.0-dev-20240920103931 → 0.0.0-dev-20241008113658

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,9 +33,15 @@ export const useQuery = (query, parameters = [], options = { runQueryOnce: false
33
33
  const [isLoading, setIsLoading] = React.useState(true);
34
34
  const [isFetching, setIsFetching] = React.useState(true);
35
35
  const [tables, setTables] = React.useState([]);
36
- const memoizedParams = React.useMemo(() => queryParameters, [...queryParameters]);
36
+ const memoizedParams = React.useMemo(() => queryParameters, [JSON.stringify(queryParameters)]);
37
37
  const memoizedOptions = React.useMemo(() => options, [JSON.stringify(options)]);
38
38
  const abortController = React.useRef(new AbortController());
39
+ const previousQueryRef = React.useRef({ sqlStatement, memoizedParams });
40
+ // Indicates that the query will be re-fetched due to a change in the query.
41
+ // Used when `isFetching` hasn't been set to true yet due to React execution.
42
+ const shouldFetch = React.useMemo(() => previousQueryRef.current.sqlStatement !== sqlStatement ||
43
+ JSON.stringify(previousQueryRef.current.memoizedParams) != JSON.stringify(memoizedParams), [powerSync, sqlStatement, memoizedParams, isFetching]);
44
+ previousQueryRef.current = { sqlStatement, memoizedParams };
39
45
  const handleResult = (result) => {
40
46
  setIsLoading(false);
41
47
  setIsFetching(false);
@@ -99,5 +105,5 @@ export const useQuery = (query, parameters = [], options = { runQueryOnce: false
99
105
  abortController.current?.abort();
100
106
  };
101
107
  }, [powerSync, sqlStatement, memoizedParams, memoizedOptions, tables]);
102
- return { isLoading, isFetching, data, error, refresh: fetchData };
108
+ return { isLoading, isFetching: isFetching || shouldFetch, data, error, refresh: fetchData };
103
109
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/react",
3
- "version": "0.0.0-dev-20240920103931",
3
+ "version": "0.0.0-dev-20241008113658",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -23,7 +23,7 @@
23
23
  "homepage": "https://docs.powersync.com",
24
24
  "peerDependencies": {
25
25
  "react": "*",
26
- "@powersync/common": "0.0.0-dev-20240920103931"
26
+ "@powersync/common": "^1.19.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@testing-library/react": "^15.0.2",