Files
nebula.js/commands/serve/web/components/Visualize/Chart.jsx
2023-01-23 16:26:40 +01:00

38 lines
638 B
JavaScript

import React, {
useEffect,
useContext,
useRef,
// useState,
} from 'react';
import NebulaContext from '../../contexts/NebulaContext';
export default function Chart({ id, onLoad }) {
const nebbie = useContext(NebulaContext);
const el = useRef();
useEffect(() => {
const n = nebbie.render({
id,
element: el.current,
});
n.then((viz) => {
onLoad(viz, el.current);
});
return () => {
n.then((v) => {
v.destroy();
});
};
}, [id]);
return (
<div
ref={el}
style={{
height: '100%',
backgroundColor: 'white',
}}
/>
);
}