@evolu/react 11.0.0-next.0 → 11.0.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Evolu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,9 +1,10 @@
1
- import { type Run } from "@evolu/common";
1
+ import { type DisposableRun, type Run } from "@evolu/common";
2
2
  import { type ReactNode } from "react";
3
3
  /**
4
4
  * Creates typed React Context and hook for {@link Run}.
5
5
  *
6
- * The `run` argument is used to infer the deps type for the returned API.
6
+ * The {@link DisposableRun} type argument is used to infer the deps type for the
7
+ * returned API, which exposes only {@link Run}.
7
8
  *
8
9
  * `useRun` throws when the provider is missing.
9
10
  *
@@ -11,7 +12,7 @@ import { type ReactNode } from "react";
11
12
  *
12
13
  * ```tsx
13
14
  * const run = createRun(createEvoluDeps());
14
- * const { RunContext, useRun } = createRunBinding(run);
15
+ * const { RunContext, useRun } = createRunBinding<typeof run>();
15
16
  *
16
17
  * <RunContext value={run}>
17
18
  * <App />
@@ -25,18 +26,18 @@ import { type ReactNode } from "react";
25
26
  *
26
27
  * ```tsx
27
28
  * const testRun = testCreateRun({ api: testApi });
28
- * const { RunContext } = createRunBinding(testRun);
29
+ * const { RunContext } = createRunBinding<typeof testRun>();
29
30
  *
30
31
  * <RunContext value={testRun}>
31
32
  * <MyComponent />
32
33
  * </RunContext>;
33
34
  * ```
34
35
  */
35
- export declare const createRunBinding: <D>(run: Run<D>) => {
36
+ export declare const createRunBinding: <R extends DisposableRun<any> = DisposableRun<unknown>>() => {
36
37
  readonly RunContext: React.FC<{
37
- readonly value: Run<D>;
38
+ readonly value: Run<R extends DisposableRun<infer D> ? D : never>;
38
39
  readonly children?: ReactNode;
39
40
  }>;
40
- readonly useRun: () => Run<D>;
41
+ readonly useRun: () => Run<R extends DisposableRun<infer D> ? D : never>;
41
42
  };
42
43
  //# sourceMappingURL=Task.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../src/Task.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,GAAG,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAEhC,KAAK,GAAG,CAAC,CAAC,CAAC,KACV;IACD,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;QAC5B,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;KAC/B,CAAC,CAAC;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;CAY/B,CAAC"}
1
+ {"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../src/Task.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,aAAa,EAAE,KAAK,GAAG,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,gBAAgB,GAC3B,CAAC,SAAS,aAAa,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,OAClD;IACH,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;QAC5B,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;QAClE,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;KAC/B,CAAC,CAAC;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;CAc1E,CAAC"}
package/dist/src/Task.js CHANGED
@@ -4,7 +4,8 @@ import { createContext, use } from "react";
4
4
  /**
5
5
  * Creates typed React Context and hook for {@link Run}.
6
6
  *
7
- * The `run` argument is used to infer the deps type for the returned API.
7
+ * The {@link DisposableRun} type argument is used to infer the deps type for the
8
+ * returned API, which exposes only {@link Run}.
8
9
  *
9
10
  * `useRun` throws when the provider is missing.
10
11
  *
@@ -12,7 +13,7 @@ import { createContext, use } from "react";
12
13
  *
13
14
  * ```tsx
14
15
  * const run = createRun(createEvoluDeps());
15
- * const { RunContext, useRun } = createRunBinding(run);
16
+ * const { RunContext, useRun } = createRunBinding<typeof run>();
16
17
  *
17
18
  * <RunContext value={run}>
18
19
  * <App />
@@ -26,16 +27,14 @@ import { createContext, use } from "react";
26
27
  *
27
28
  * ```tsx
28
29
  * const testRun = testCreateRun({ api: testApi });
29
- * const { RunContext } = createRunBinding(testRun);
30
+ * const { RunContext } = createRunBinding<typeof testRun>();
30
31
  *
31
32
  * <RunContext value={testRun}>
32
33
  * <MyComponent />
33
34
  * </RunContext>;
34
35
  * ```
35
36
  */
36
- export const createRunBinding = (
37
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
- run) => {
37
+ export const createRunBinding = () => {
39
38
  const RunContext = createContext(null);
40
39
  return {
41
40
  RunContext,
@@ -1,4 +1,4 @@
1
- export * from "./local-first/createEvoluBinding.js";
2
- export * from "./local-first/useIsSsr.js";
3
- export * from "./Task.js";
1
+ export * from "./local-first/createEvoluBinding.tsx";
2
+ export * from "./local-first/useIsSsr.ts";
3
+ export * from "./Task.tsx";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC"}
@@ -58,7 +58,15 @@ export interface ReactBinding<S extends EvoluSchema = EvoluSchema> {
58
58
  * The created binding contains the context component and all hooks needed by
59
59
  * React components using an {@link Evolu} instance created from that schema.
60
60
  *
61
- * TODO: Example from playground example.
61
+ * The {@link EvoluSchema} type argument configures the binding without passing
62
+ * the schema at runtime.
63
+ *
64
+ * ### Example
65
+ *
66
+ * ```tsx
67
+ * const { EvoluContext, useEvolu, useQuery } =
68
+ * createEvoluBinding<typeof AppSchema>();
69
+ * ```
62
70
  */
63
- export declare const createEvoluBinding: <S extends EvoluSchema>(schema: S) => ReactBinding<S>;
71
+ export declare const createEvoluBinding: <S extends EvoluSchema = EvoluSchema>() => ReactBinding<S>;
64
72
  //# sourceMappingURL=createEvoluBinding.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createEvoluBinding.d.ts","sourceRoot":"","sources":["../../../src/local-first/createEvoluBinding.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACX,OAAO,EACP,kBAAkB,EAClB,0BAA0B,EAC1B,KAAK,EACL,SAAS,EACT,GAAG,EACJ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAGf,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IAC/D,2EAA2E;IAC3E,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;QAC9B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;KAC/B,CAAC,CAAC;IAEH,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,EAAE,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;IAElC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,GAAG,EAC/B,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAClB,OAAO,CAAC,EAAE,OAAO,CAAC;QAChB,sCAAsC;QACtC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;QAEvB,4EAA4E;QAC5E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;KACzC,CAAC,KACC,SAAS,CAAC,CAAC,CAAC,CAAC;IAElB;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,SAAS,OAAO,CAAC,CAAC,CAAC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jB,GAAG,0BAA0B,CAAC,CAAC,CAAC;YAChC,GAAG,0BAA0B,CAAC,EAAE,CAAC;SAClC,CAAC;KACH,CAAC,KACC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,EAAE,GAAG,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC;IAE3D,4DAA4D;IAC5D,QAAQ,CAAC,oBAAoB,EAAE,CAAC,CAAC,SAAS,GAAG,EAC3C,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAClB,OAAO,CAAC,EAAE,OAAO,CAAC;QAChB;;;WAGG;QACH,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;KACxB,CAAC,KACC,SAAS,CAAC,CAAC,CAAC,CAAC;IAElB,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,EAAE,CACjB,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EAC1C,UAAU,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,KAC7C,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,GAC7B,CAAC,SAAS,WAAW,GAAG,WAAW,OAChC,YAAY,CAAC,CAAC,CAiGlB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { assert, emptyArray, lazyVoid } from "@evolu/common";
2
+ import { constVoid, assert, emptyArray } from "@evolu/common";
3
3
  import { createContext, use, useEffect, useMemo, useRef, useSyncExternalStore, } from "react";
4
4
  import { useIsSsr } from "./useIsSsr.js";
5
5
  /**
@@ -8,11 +8,17 @@ import { useIsSsr } from "./useIsSsr.js";
8
8
  * The created binding contains the context component and all hooks needed by
9
9
  * React components using an {@link Evolu} instance created from that schema.
10
10
  *
11
- * TODO: Example from playground example.
11
+ * The {@link EvoluSchema} type argument configures the binding without passing
12
+ * the schema at runtime.
13
+ *
14
+ * ### Example
15
+ *
16
+ * ```tsx
17
+ * const { EvoluContext, useEvolu, useQuery } =
18
+ * createEvoluBinding<typeof AppSchema>();
19
+ * ```
12
20
  */
13
- export const createEvoluBinding = (
14
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
- schema) => {
21
+ export const createEvoluBinding = () => {
16
22
  const EvoluContext = createContext(null);
17
23
  const useEvolu = () => {
18
24
  const evolu = use(EvoluContext);
@@ -24,7 +30,7 @@ schema) => {
24
30
  const { once } = useRef(options).current;
25
31
  if (once) {
26
32
  /* eslint-disable react-hooks/rules-of-hooks */
27
- useEffect(() => evolu.subscribeQuery(query)(lazyVoid), [evolu, query]);
33
+ useEffect(() => evolu.subscribeQuery(query)(constVoid), [evolu, query]);
28
34
  return evolu.getQueryRows(query);
29
35
  }
30
36
  return useSyncExternalStore(useMemo(() => evolu.subscribeQuery(query), [evolu, query]), useMemo(() => () => evolu.getQueryRows(query), [evolu, query]), () => emptyArray);
@@ -1 +1 @@
1
- {"version":3,"file":"useIsSsr.d.ts","sourceRoot":"","sources":["../../../src/local-first/useIsSsr.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAO,OAE+B,CAAC"}
1
+ {"version":3,"file":"useIsSsr.d.ts","sourceRoot":"","sources":["../../../src/local-first/useIsSsr.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAO,OAEiC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { lazyFalse, lazyTrue } from "@evolu/common";
1
+ import { constFalse, constTrue } from "@evolu/common";
2
2
  import { useSyncExternalStore } from "react";
3
3
  // eslint-disable-next-line @typescript-eslint/no-empty-function
4
4
  const emptySubscribe = () => () => { };
@@ -9,4 +9,4 @@ const emptySubscribe = () => () => { };
9
9
  */
10
10
  export const useIsSsr = () =>
11
11
  // TODO: Consider useDeferredValue(isSSRSync);
12
- useSyncExternalStore(emptySubscribe, lazyFalse, lazyTrue);
12
+ useSyncExternalStore(emptySubscribe, constFalse, constTrue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evolu/react",
3
- "version": "11.0.0-next.0",
3
+ "version": "11.0.0",
4
4
  "description": "Evolu for React",
5
5
  "keywords": [
6
6
  "evolu",
@@ -9,7 +9,10 @@
9
9
  ],
10
10
  "author": "Daniel Steigerwald <daniel@steigerwald.cz>",
11
11
  "license": "MIT",
12
- "repository": "evoluhq/evolu",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/evoluhq/evolu.git"
15
+ },
13
16
  "bugs": {
14
17
  "url": "https://github.com/evoluhq/evolu/issues"
15
18
  },
@@ -29,18 +32,13 @@
29
32
  "src/**",
30
33
  "README.md"
31
34
  ],
32
- "scripts": {
33
- "build": "tsc --build tsconfig.build.json",
34
- "prepack": "npm run build",
35
- "format": "prettier --write \"src/*.{ts,tsx,md}\""
36
- },
37
35
  "devDependencies": {
38
- "@evolu/common": "8.0.0-next.0",
39
- "@evolu/typescript-config": "*",
40
- "@types/react": "^19.2.14",
41
- "@types/react-dom": "^19.2.3",
42
- "react": "^19.2.4",
43
- "typescript": "^5.9.3"
36
+ "@types/react": "^19.2.18",
37
+ "@types/react-dom": "^19.2.4",
38
+ "@typescript/native": "npm:typescript@^7.0.2",
39
+ "react": "19.2.3",
40
+ "@evolu/common": "8.0.0",
41
+ "@evolu/typescript-config": "0.0.2"
44
42
  },
45
43
  "peerDependencies": {
46
44
  "@evolu/common": "^8.0.0-next.0",
@@ -52,5 +50,9 @@
52
50
  "engines": {
53
51
  "node": ">=24.0.0"
54
52
  },
55
- "sideEffects": false
56
- }
53
+ "sideEffects": false,
54
+ "scripts": {
55
+ "build": "tsc --build tsconfig.build.json",
56
+ "format": "prettier --write \"src/*.{ts,tsx,md}\""
57
+ }
58
+ }
package/src/Task.tsx CHANGED
@@ -1,12 +1,13 @@
1
1
  "use client";
2
2
 
3
- import { assert, type Run } from "@evolu/common";
3
+ import { assert, type DisposableRun, type Run } from "@evolu/common";
4
4
  import { createContext, use, type ReactNode } from "react";
5
5
 
6
6
  /**
7
7
  * Creates typed React Context and hook for {@link Run}.
8
8
  *
9
- * The `run` argument is used to infer the deps type for the returned API.
9
+ * The {@link DisposableRun} type argument is used to infer the deps type for the
10
+ * returned API, which exposes only {@link Run}.
10
11
  *
11
12
  * `useRun` throws when the provider is missing.
12
13
  *
@@ -14,7 +15,7 @@ import { createContext, use, type ReactNode } from "react";
14
15
  *
15
16
  * ```tsx
16
17
  * const run = createRun(createEvoluDeps());
17
- * const { RunContext, useRun } = createRunBinding(run);
18
+ * const { RunContext, useRun } = createRunBinding<typeof run>();
18
19
  *
19
20
  * <RunContext value={run}>
20
21
  * <App />
@@ -28,23 +29,24 @@ import { createContext, use, type ReactNode } from "react";
28
29
  *
29
30
  * ```tsx
30
31
  * const testRun = testCreateRun({ api: testApi });
31
- * const { RunContext } = createRunBinding(testRun);
32
+ * const { RunContext } = createRunBinding<typeof testRun>();
32
33
  *
33
34
  * <RunContext value={testRun}>
34
35
  * <MyComponent />
35
36
  * </RunContext>;
36
37
  * ```
37
38
  */
38
- export const createRunBinding = <D,>(
39
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
40
- run: Run<D>,
41
- ): {
39
+ export const createRunBinding = <
40
+ R extends DisposableRun<any> = DisposableRun<unknown>,
41
+ >(): {
42
42
  readonly RunContext: React.FC<{
43
- readonly value: Run<D>;
43
+ readonly value: Run<R extends DisposableRun<infer D> ? D : never>;
44
44
  readonly children?: ReactNode;
45
45
  }>;
46
- readonly useRun: () => Run<D>;
46
+ readonly useRun: () => Run<R extends DisposableRun<infer D> ? D : never>;
47
47
  } => {
48
+ type D = R extends DisposableRun<infer D> ? D : never;
49
+
48
50
  const RunContext = createContext<Run<D> | null>(null);
49
51
 
50
52
  return {
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./local-first/createEvoluBinding.js";
2
- export * from "./local-first/useIsSsr.js";
3
- export * from "./Task.js";
1
+ export * from "./local-first/createEvoluBinding.tsx";
2
+ export * from "./local-first/useIsSsr.ts";
3
+ export * from "./Task.tsx";
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { assert, emptyArray, lazyVoid } from "@evolu/common";
3
+ import { constVoid, assert, emptyArray } from "@evolu/common";
4
4
  import type {
5
5
  Evolu,
6
6
  EvoluSchema,
@@ -20,7 +20,7 @@ import {
20
20
  useSyncExternalStore,
21
21
  type ReactNode,
22
22
  } from "react";
23
- import { useIsSsr } from "./useIsSsr.js";
23
+ import { useIsSsr } from "./useIsSsr.ts";
24
24
 
25
25
  export interface ReactBinding<S extends EvoluSchema = EvoluSchema> {
26
26
  /** Provides {@link Evolu} to React descendants consumed via `useEvolu`. */
@@ -100,12 +100,19 @@ export interface ReactBinding<S extends EvoluSchema = EvoluSchema> {
100
100
  * The created binding contains the context component and all hooks needed by
101
101
  * React components using an {@link Evolu} instance created from that schema.
102
102
  *
103
- * TODO: Example from playground example.
103
+ * The {@link EvoluSchema} type argument configures the binding without passing
104
+ * the schema at runtime.
105
+ *
106
+ * ### Example
107
+ *
108
+ * ```tsx
109
+ * const { EvoluContext, useEvolu, useQuery } =
110
+ * createEvoluBinding<typeof AppSchema>();
111
+ * ```
104
112
  */
105
- export const createEvoluBinding = <S extends EvoluSchema>(
106
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
107
- schema: S,
108
- ): ReactBinding<S> => {
113
+ export const createEvoluBinding = <
114
+ S extends EvoluSchema = EvoluSchema,
115
+ >(): ReactBinding<S> => {
109
116
  const EvoluContext = createContext<Evolu<S> | null>(null);
110
117
 
111
118
  const useEvolu = (): Evolu<S> => {
@@ -125,7 +132,7 @@ export const createEvoluBinding = <S extends EvoluSchema>(
125
132
 
126
133
  if (once) {
127
134
  /* eslint-disable react-hooks/rules-of-hooks */
128
- useEffect(() => evolu.subscribeQuery(query)(lazyVoid), [evolu, query]);
135
+ useEffect(() => evolu.subscribeQuery(query)(constVoid), [evolu, query]);
129
136
  return evolu.getQueryRows(query);
130
137
  }
131
138
 
@@ -1,4 +1,4 @@
1
- import { lazyFalse, lazyTrue } from "@evolu/common";
1
+ import { constFalse, constTrue } from "@evolu/common";
2
2
  import { useSyncExternalStore } from "react";
3
3
 
4
4
  // eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -11,4 +11,4 @@ const emptySubscribe = () => () => {};
11
11
  */
12
12
  export const useIsSsr = (): boolean =>
13
13
  // TODO: Consider useDeferredValue(isSSRSync);
14
- useSyncExternalStore(emptySubscribe, lazyFalse, lazyTrue);
14
+ useSyncExternalStore(emptySubscribe, constFalse, constTrue);