mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
feat(ui): iterate on picker
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,32 +0,0 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
const isInitialValueFunction = <T>(value: T | (() => T)): value is () => T => {
|
||||
return typeof value === 'function';
|
||||
};
|
||||
|
||||
/**
|
||||
* Extension of useState that provides imperative access to state value.
|
||||
*
|
||||
* @param initialValue - Initial state value or function that returns it
|
||||
* @returns [state, setState, getState] - Standard state tuple plus getter
|
||||
*
|
||||
* @remarks
|
||||
* - Only use getState() in event handlers and effects, not during rendering
|
||||
* - In Concurrent Mode, getState() may return stale values before commit
|
||||
*/
|
||||
export const useStateImperative = <T>(
|
||||
initialValue: T | (() => T)
|
||||
): readonly [T, (newValue: T | ((prevState: T) => T)) => void, () => T] => {
|
||||
const [state, setState] = useState(isInitialValueFunction(initialValue) ? initialValue() : initialValue);
|
||||
const stateRef = useRef(state);
|
||||
|
||||
useEffect(() => {
|
||||
stateRef.current = state;
|
||||
}, [state]);
|
||||
|
||||
const getState = useCallback(() => {
|
||||
return stateRef.current;
|
||||
}, []);
|
||||
|
||||
return [state, setState, getState] as const;
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
import { forwardRef } from 'react';
|
||||
|
||||
/**
|
||||
* A forwardRef that works with generics and doesn't require the use of `as` to cast the type.
|
||||
* See: https://www.totaltypescript.com/forwardref-with-generic-components
|
||||
*/
|
||||
export function fixedForwardRef<T, P = object>(
|
||||
render: (props: P, ref: React.Ref<T>) => React.ReactNode
|
||||
): (props: P & React.RefAttributes<T>) => React.ReactNode {
|
||||
// @ts-expect-error: This is a workaround for forwardRef's crappy typing
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return forwardRef(render) as any;
|
||||
}
|
||||
Reference in New Issue
Block a user