refactor(useConnection): return internal node, add node generic
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { shallow } from 'zustand/shallow';
|
||||
|
||||
import { useStore } from './useStore';
|
||||
import type { ReactFlowStore } from '../types/store';
|
||||
import { ConnectionState, pointToRendererPoint } from '@xyflow/system';
|
||||
|
||||
const selector = (s: ReactFlowStore): ConnectionState => {
|
||||
import { useStore } from './useStore';
|
||||
import type { InternalNode, Node, ReactFlowStore } from '../types';
|
||||
|
||||
const selector = (s: ReactFlowStore) => {
|
||||
return s.connection.inProgress
|
||||
? { ...s.connection, to: pointToRendererPoint(s.connection.to, s.transform) }
|
||||
: { ...s.connection };
|
||||
@@ -15,6 +15,6 @@ const selector = (s: ReactFlowStore): ConnectionState => {
|
||||
* @public
|
||||
* @returns ConnectionState
|
||||
*/
|
||||
export function useConnection(): ConnectionState {
|
||||
return useStore(selector, shallow);
|
||||
export function useConnection<NodeType extends Node = Node>(): ConnectionState<InternalNode<NodeType>> {
|
||||
return useStore(selector, shallow) as ConnectionState<InternalNode<NodeType>>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user