mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-22 19:24:21 -05:00
38 lines
638 B
JavaScript
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',
|
|
}}
|
|
/>
|
|
);
|
|
}
|