feat(onError): add onError prop #2772

This commit is contained in:
moklick
2023-01-25 17:47:42 +01:00
parent 3d6937b3e4
commit 9527261719
20 changed files with 68 additions and 42 deletions
@@ -1,8 +1,8 @@
import { useMemo } from 'react';
import { devWarn } from '../../utils';
import { MarkerType } from '../../types';
import type { EdgeMarker } from '../../types';
import { useStoreApi } from '../../hooks/useStore';
type SymbolProps = Omit<EdgeMarker, 'type'>;
@@ -38,11 +38,12 @@ export const MarkerSymbols = {
};
export function useMarkerSymbol(type: MarkerType) {
const store = useStoreApi();
const symbol = useMemo(() => {
const symbolExists = Object.prototype.hasOwnProperty.call(MarkerSymbols, type);
if (!symbolExists) {
devWarn(`Marker type "${type}" doesn't exist. Help: https://reactflow.dev/error#900`);
store.getState().onError?.('009', `Marker type "${type}" doesn't exist.`);
return null;
}