// Copyright (C) 2021, Mindee. // This program is licensed under the Apache License version 2. // See LICENSE or go to for full license details. import { MutableRefObject, useRef, useState } from "react"; export function useStateWithRef( initialState: T ): [T, (value: T) => void, MutableRefObject] { const [state, setState] = useState(initialState); const ref = useRef(initialState); const handleState = (value: T) => { ref.current = value; setState(value); }; return [state, handleState, ref]; }