@neo4j-nvl/react
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -70,3 +70,5 @@ import { NamedExoticComponent } from 'react'; | ||
nvlOptions?: NvlOptions; | ||
/** A callback to handle any errors that happen during NVL initialization */ | ||
onInitializationError?: (error: unknown) => void; | ||
}>; | ||
export { BasicNvlWrapper }; |
@@ -59,3 +59,3 @@ import React, { useEffect, useState, useRef, forwardRef, useImperativeHandle, memo } from 'react'; | ||
*/ | ||
const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOptions, nvlCallbacks = {}, nvlOptions }, ref) => { | ||
const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOptions, nvlCallbacks = {}, nvlOptions, onInitializationError }, ref) => { | ||
useImperativeHandle(ref, () => { | ||
@@ -75,8 +75,19 @@ const nvlMethods = Object.getOwnPropertyNames(NVL.prototype); | ||
} | ||
const newNvl = new NVL(containerRef.current, currentNodes, currentRels, combinedOptions, nvlCallbacks); | ||
setNvl(newNvl); | ||
setCurrentRels(rels); | ||
setCurrentNodes(nodes); | ||
let newNvl; | ||
try { | ||
newNvl = new NVL(containerRef.current, currentNodes, currentRels, combinedOptions, nvlCallbacks); | ||
setNvl(newNvl); | ||
setCurrentRels(rels); | ||
setCurrentNodes(nodes); | ||
} | ||
catch (e) { | ||
if (typeof onInitializationError === 'function') { | ||
onInitializationError(e); | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
return () => { | ||
newNvl.destroy(); | ||
newNvl === null || newNvl === void 0 ? void 0 : newNvl.destroy(); | ||
}; | ||
@@ -83,0 +94,0 @@ } |
{ | ||
"name": "@neo4j-nvl/react", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
11261
286