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.
portainer/app/react/hooks/useStateWrapper.ts

20 lines
460 B

import { useState, useCallback, useEffect } from 'react';
export function useStateWrapper<T>(value: T, onChange: (value: T) => void) {
const [inputValue, setInputValue] = useState(value);
const updateInputValue = useCallback(
(value: T) => {
setInputValue(value);
onChange(value);
},
[onChange, setInputValue]
);
useEffect(() => {
setInputValue(value);
}, [value]);
return [inputValue, updateInputValue] as const;
}