Files
xyflow/packages/react/src/hooks/useConnection.ts
2024-06-24 16:37:11 +02:00

21 lines
519 B
TypeScript

import { shallow } from 'zustand/shallow';
import { useStore } from './useStore';
import type { ReactFlowStore } from '../types/store';
import { ConnectionState } from '@xyflow/system';
const selector = (s: ReactFlowStore) => ({
...s.connection,
inProgress: s.connection.fromHandle !== null,
});
/**
* Hook for accessing the ongoing connection.
*
* @public
* @returns ongoing connection
*/
export function useConnection(): ConnectionState & { inProgress: boolean } {
return useStore(selector, shallow);
}