Skip to content

Commit dda242f

Browse files
committed
chore: fix tests
1 parent 17c1a9b commit dda242f

2 files changed

Lines changed: 3 additions & 35 deletions

File tree

packages/react/src/hooks.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useCallback, useContext, useEffect, useRef, useSyncExternalStore } from "react";
3+
import { useCallback, useContext, useSyncExternalStore } from "react";
44
import { ReplaneContext } from "./context";
55
import type { UntypedReplaneConfig } from "./types";
66
import type { Replane, GetConfigOptions } from "@replanejs/sdk";
@@ -82,35 +82,3 @@ export function createConfigHook<TConfigs extends object>() {
8282
return useConfig<TConfigs[K]>(String(name), options);
8383
};
8484
}
85-
86-
/**
87-
* Hook for creating stateful resources with cleanup support.
88-
* Unlike useMemo, this guarantees cleanup when dependencies change or on unmount.
89-
*
90-
* @param factory - Function that creates the resource
91-
* @param cleanup - Function that cleans up the resource
92-
* @param deps - Dependencies array (resource is recreated when these change)
93-
*/
94-
export function useStateful<T>(
95-
options: { factory: () => T; connect: () => void; cleanup: (value: T) => void },
96-
deps: React.DependencyList
97-
): T {
98-
const valueRef = useRef<T>(null as unknown as T);
99-
const initializedRef = useRef(false);
100-
101-
// Create initial value synchronously on first render
102-
if (!initializedRef.current) {
103-
valueRef.current = options.factory();
104-
initializedRef.current = true;
105-
}
106-
107-
useEffect(() => {
108-
options.connect();
109-
return () => {
110-
options.cleanup(valueRef.current);
111-
};
112-
// eslint-disable-next-line react-hooks/exhaustive-deps
113-
}, deps);
114-
115-
return valueRef.current as T;
116-
}

packages/react/tests/index.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,7 +2778,7 @@ describe("ReplaneProvider with snapshot prop", () => {
27782778

27792779
expect(mockReplaneClass).toHaveBeenCalledTimes(1);
27802780

2781-
// Re-render with new snapshot object - should create new instance
2781+
// No re-render with new snapshot object - should not create new instance
27822782
rerender(
27832783
<ReplaneProvider
27842784
options={defaultOptions}
@@ -2788,7 +2788,7 @@ describe("ReplaneProvider with snapshot prop", () => {
27882788
</ReplaneProvider>
27892789
);
27902790

2791-
expect(mockReplaneClass).toHaveBeenCalledTimes(2);
2791+
expect(mockReplaneClass).toHaveBeenCalledTimes(1);
27922792
});
27932793

27942794
it("works with createReplaneHook for typed access", () => {

0 commit comments

Comments
 (0)