Skip to content

Commit

Permalink
fix: improve the handling of the observable query subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
runeb committed Mar 23, 2021
1 parent 4251fbe commit e951cb2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/useSecrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ export function useSecrets<T>(namespace: string) {

const id = `secrets.${namespace}`;

let subscription: any;
useEffect(() => {
subscription = client.observable
let subscription = client.observable
.listen(query, { id }, { visibility: 'query' })
.subscribe((result: Record<string, any>) => {
setSecrets(result?.result?.secrets);
});
return () => {
subscription.unsubscribe();
};
}, []);
}, [id]);

useEffect(() => {
async function fetchData() {
Expand All @@ -30,7 +29,7 @@ export function useSecrets<T>(namespace: string) {
.finally(() => setLoading(false));
}
fetchData();
}, []);
}, [id]);

const storeSecrets = (secrets: T) => {
setLoading(true);
Expand Down

0 comments on commit e951cb2

Please sign in to comment.