mirror of
https://github.com/bendtherules/multimeter-connect-web.git
synced 2026-08-19 00:33:10 +00:00
Refactor code + add auto-retry
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
MutableRefObject,
|
||||
useRef,
|
||||
useState,
|
||||
Dispatch,
|
||||
SetStateAction,
|
||||
} from "react";
|
||||
|
||||
export function useStateWithRef<TState>(
|
||||
initialValue: TState,
|
||||
): [TState, Dispatch<SetStateAction<TState>>, MutableRefObject<TState>] {
|
||||
const [value, setValue] = useState<TState>(initialValue);
|
||||
const valueRef = useRef<TState>(initialValue);
|
||||
valueRef.current = value;
|
||||
|
||||
return [value, setValue, valueRef];
|
||||
}
|
||||
Reference in New Issue
Block a user