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/useReactiveValue.js

16 lines
419 B

import { useState } from 'react';
import { useAutorun } from './useAutorun';
import { useNonReactiveValue } from './useNonReactiveValue';
export const useReactiveValue = (getValue, deps = []) => {
const initialValue = useNonReactiveValue(getValue);
const [value, setValue] = useState(() => initialValue);
useAutorun(() => {
const newValue = getValue();
setValue(() => newValue);
}, deps);
return value;
};