feat(react): infer node types from passed nodes

This commit is contained in:
moklick
2024-01-24 18:25:31 +01:00
parent 8983d64397
commit a345b2670b
15 changed files with 364 additions and 354 deletions
+3 -3
View File
@@ -1,15 +1,15 @@
import { useEffect, useRef } from 'react';
import { useReactFlow } from './useReactFlow';
import type { OnInit } from '../types';
import type { OnInit, Node } from '../types';
/**
* Hook for calling onInit handler.
*
* @internal
*/
export function useOnInitHandler(onInit: OnInit | undefined) {
const rfInstance = useReactFlow();
export function useOnInitHandler<NodeType extends Node = Node>(onInit: OnInit<NodeType> | undefined) {
const rfInstance = useReactFlow<NodeType>();
const isInitialized = useRef<boolean>(false);
useEffect(() => {