Skip to content

Commit

Permalink
add usecallback to avoid rerenders and make hydrator optional (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliusKoronciCH authored Apr 4, 2024
1 parent 296d13c commit a99809f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function createEventStore<T extends object>(
initialState: T,
options?: {
debug?: boolean;
hydrator: () => Promise<T>;
hydrator?: () => Promise<T>;
persist?: (state: T) => Promise<void>;
},
) {
Expand Down Expand Up @@ -134,9 +134,9 @@ export function createEventStore<T extends object>(
return [value, handleUpdate];
};
const useHydrateStore = () => {
return (payload: T) => {
return useCallback((payload: T) => {
globalEventStore.next({ type: '@@HYDRATED', payload });
};
}, []);
};
const useIsHydrated = () => {
const [isHydrated, setIsHydrated] = useState(false);
Expand Down

0 comments on commit a99809f

Please sign in to comment.