1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

fix(stack/git): unexpected cursor movement in git text fields [EE-5143] (#8655)

This commit is contained in:
Oscar Zhou 2023-03-20 10:00:49 +13:00 committed by GitHub
parent 45def82156
commit 124e0bf9b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 24 deletions

View file

@ -0,0 +1,19 @@
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;
}