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:
parent
45def82156
commit
124e0bf9b9
6 changed files with 37 additions and 24 deletions
19
app/react/hooks/useStateWrapper.ts
Normal file
19
app/react/hooks/useStateWrapper.ts
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue