@@ -25,10 +25,10 @@ handle.updateArgs([{ config: 'newValue' }]);
2525handle .remove ();
2626
2727// Get all hook results
28- const results = manager .getHookResults () ;
28+ const results = manager .hookResults ;
2929
3030// Clean up all hooks (do this on unmount)
31- useEffect (() => () => manager .cleanup (), [manager ]);
31+ useEffect (() => () => manager .cleanup (), [manager . cleanup ]);
3232```
3333
3434** When to use:** Managing multiple remote hooks dynamically, adding/removing hooks at runtime, or building plugin systems.
@@ -48,10 +48,10 @@ import { useRemoteHookManager } from '@scalprum/react-core';
4848import { useEffect } from ' react' ;
4949
5050function HookManagerComponent() {
51- const manager = useRemoteHookManager ();
51+ const { addHook, cleanup, hookResults } = useRemoteHookManager ();
5252
5353 const addCounterHook = () => {
54- const handle = manager . addHook ({
54+ const handle = addHook ({
5555 scope: ' counter-app' ,
5656 module: ' ./useCounter' ,
5757 args: [{ initialValue: 0 , step: 1 }]
@@ -62,18 +62,17 @@ function HookManagerComponent() {
6262 };
6363
6464 const getAllResults = () => {
65- const results = manager .getHookResults ();
66- console .log (' All hook results:' , results );
65+ console .log (' All hook results:' , hookResults );
6766 };
6867
6968 const cleanupAll = () => {
70- manager . cleanup ();
69+ cleanup ();
7170 };
7271
7372 // Cleanup on unmount
7473 useEffect (() => {
75- return () => manager . cleanup ();
76- }, [manager ]);
74+ return () => cleanup ();
75+ }, [cleanup ]);
7776
7877 return (
7978 <div >
@@ -108,9 +107,9 @@ Adds a new remote hook and returns a handle to control it.
108107- ` remove() ` : Remove this specific hook
109108- ` updateArgs(args: any[]) ` : Update arguments for this hook
110109
111- #### ` getHookResults() : UseRemoteHookResult<any>[]`
110+ #### ` hookResults : UseRemoteHookResult<any>[]`
112111
113- Returns an array of all current hook results.
112+ An array of all current hook results.
114113
115114** Returns:** Array of ` UseRemoteHookResult ` objects with:
116115- ` id ` : Unique hook identifier
@@ -170,16 +169,12 @@ function MultiHookManager() {
170169 setHooks (prev => prev .filter ((_ , i ) => i !== index ));
171170 };
172171
173- const getAllResults = () => {
174- return manager .getHookResults ();
175- };
176-
177172 // Cleanup on unmount
178173 useEffect (() => {
179174 return () => manager .cleanup ();
180- }, [manager ]);
175+ }, [manager . cleanup ]);
181176
182- const hookResults = getAllResults () ;
177+ const { hookResults } = manager ;
183178
184179 return (
185180 <div >
@@ -237,7 +232,7 @@ function DynamicArgsManager() {
237232 setHandles (prev => prev .filter ((_ , i ) => i !== index ));
238233 };
239234
240- const hookResults = manager . getHookResults () ;
235+ const { hookResults } = manager ;
241236
242237 return (
243238 <div >
@@ -287,7 +282,7 @@ function HookResultsProcessor() {
287282
288283 useEffect (() => {
289284 // Process hook results whenever they change
290- const results = manager .getHookResults () ;
285+ const results = manager .hookResults ;
291286
292287 const processed = results .reduce ((acc , result , index ) => {
293288 if (! result .loading && ! result .error && result .hookResult ) {
@@ -302,7 +297,7 @@ function HookResultsProcessor() {
302297 }, {});
303298
304299 setProcessedData (processed );
305- }, [manager ]); // Re-run when results change
300+ }, [manager . hookResults ]); // Re-run when results change
306301
307302 const determineHookType = (hookResult ) => {
308303 if (typeof hookResult .count === ' number' ) return ' counter' ;
@@ -380,7 +375,6 @@ function MemoizedArgsExample() {
380375## Performance Considerations
381376
382377- ** Manager Stability** : The manager object is stable across re-renders
383- - ** Hook Results** : Call ` getHookResults() ` to get fresh results, as they're not automatically reactive
384378- ** Memory Management** : Always call ` cleanup() ` or individual ` remove() ` methods to prevent memory leaks
385379- ** Argument Updates** : Use ` handle.updateArgs() ` to update arguments instead of removing and re-adding hooks
386380
@@ -414,31 +408,11 @@ function MemoizedArgsExample() {
414408
415409``` tsx
416410function ErrorHandlingManager() {
417- const manager = useRemoteHookManager ();
418- const [errors, setErrors] = useState ([]);
419-
420- const addHookWithErrorHandling = (config ) => {
421- try {
422- const handle = manager .addHook (config );
423-
424- // Check results periodically for errors
425- setTimeout (() => {
426- const results = manager .getHookResults ();
427- const newErrors = results
428- .filter (result => result .error )
429- .map (result => ({ id: result .id , error: result .error .message }));
430-
431- if (newErrors .length > 0 ) {
432- setErrors (prev => [... prev , ... newErrors ]);
433- }
434- }, 1000 );
435-
436- return handle ;
437- } catch (error ) {
438- console .error (' Failed to add hook:' , error );
439- setErrors (prev => [... prev , { id: ' add-hook' , error: error .message }]);
440- }
441- };
411+ const { hookResults } = useRemoteHookManager ();
412+
413+ const errors = hookResults
414+ .filter (result => result .error )
415+ .map (result => ({ id: result .id , error: result .error .message }));
442416
443417 return (
444418 <div >
0 commit comments