Spaces:
Sleeping
Sleeping
yassinekolsi
Fix all TypeScript errors: remove unused imports, delete orphan reactflow components
532554f | import * as React from 'react'; | |
| interface CommonControlledStateProps<T> { | |
| value?: T; | |
| defaultValue?: T; | |
| } | |
| export function useControlledState<T, Rest extends unknown[] = []>( | |
| props: CommonControlledStateProps<T> & { | |
| onChange?: (value: T, ...args: Rest) => void; | |
| }, | |
| ): readonly [T, (next: T, ...args: Rest) => void] { | |
| const { value, defaultValue, onChange } = props; | |
| const [state, setInternalState] = React.useState<T>( | |
| value !== undefined ? value : (defaultValue as T), | |
| ); | |
| React.useEffect(() => { | |
| if (value !== undefined) setInternalState(value); | |
| }, [value]); | |
| const setState = React.useCallback( | |
| (next: T, ...args: Rest) => { | |
| setInternalState(next); | |
| onChange?.(next, ...args); | |
| }, | |
| [onChange], | |
| ); | |
| return [state, setState] as const; | |
| } | |