The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/hooks/useObservableValue.js

22 lines
428 B

import { useEffect, useState } from 'react';
export const useObservableValue = (getValue) => {
const [value, setValue] = useState(() => getValue());
useEffect(() => {
let mounted = true;
const unsubscribe = getValue((newValue) => {
if (mounted) {
setValue(newValue);
}
});
return () => {
mounted = false;
typeof unsubscribe === 'function' && unsubscribe();
};
}, [getValue]);
return value;
};