|
1 | 1 | "use client"; |
2 | 2 |
|
3 | | -import { useCallback, useContext, useEffect, useRef, useSyncExternalStore } from "react"; |
| 3 | +import { useCallback, useContext, useSyncExternalStore } from "react"; |
4 | 4 | import { ReplaneContext } from "./context"; |
5 | 5 | import type { UntypedReplaneConfig } from "./types"; |
6 | 6 | import type { Replane, GetConfigOptions } from "@replanejs/sdk"; |
@@ -82,35 +82,3 @@ export function createConfigHook<TConfigs extends object>() { |
82 | 82 | return useConfig<TConfigs[K]>(String(name), options); |
83 | 83 | }; |
84 | 84 | } |
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 | | -} |
0 commit comments