Skip to content

Commit

Permalink
add deps
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefED committed May 2, 2021
1 parent 2bbf54e commit 9866bd8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/reactive-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
"last 1 safari version"
]
},
"gitHead": "cf55e881a5e838ebf4eefab1e0a6cc4308583643"
"gitHead": "2bbf54e128038b21a9ac051c144ab5ed253e9ba4"
}
8 changes: 4 additions & 4 deletions packages/reactive-react/src/useReactive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo, useReducer } from "react";
import { reactive } from "@reactivedata/reactive";

export function useReactive<T>(stateObject: T): T {
export function useReactive<T>(stateObject: T, deps?: React.DependencyList): T {
const [, forceUpdate] = useReducer((c) => c + 1, 0);

const ret = useMemo(() => {
Expand All @@ -10,12 +10,12 @@ export function useReactive<T>(stateObject: T): T {
forceUpdate();
},
});
}, [stateObject]);
}, deps || []);

return ret;
}

export function useReactives<T extends any[]>(...stateObjects: T): T {
export function useReactives<T extends any[]>(stateObjects: T, deps?: React.DependencyList): T {
const [, forceUpdate] = useReducer((c) => c + 1, 0);
const trigger = {
trigger: () => {
Expand All @@ -27,5 +27,5 @@ export function useReactives<T extends any[]>(...stateObjects: T): T {
return stateObjects.map((stateObject) => {
return reactive(stateObject, trigger);
});
}, stateObjects) as T;
}, deps || []) as T;
}

0 comments on commit 9866bd8

Please sign in to comment.