Skip to content

Commit

Permalink
Test in strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Sep 20, 2023
1 parent ae349c4 commit f3f8e87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
22 changes: 12 additions & 10 deletions src/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ export const Chart = forwardRef<ChartRef, ChartProps>((props, ref) => {
const [init, setInit] = useState(false);

useEffect(() => {
if (containerRef.current) {
chartRef.current = new G2Chart({
container: containerRef.current,
renderer,
});
setInit(true);
}
if (chartRef.current || !containerRef.current) return;
chartRef.current = new G2Chart({
container: containerRef.current,
renderer,
});
setInit(true);
return () => {
if (chartRef.current) chartRef.current.destroy();
if (chartRef.current) {
chartRef.current.destroy();
chartRef.current = undefined;
}
};
}, []);
}, [renderer]);

useEffect(() => {
if (init) onInit?.();
}, [init]);
}, [init, onInit]);

useEffect(() => {
if (chartRef.current && options) {
Expand Down
8 changes: 6 additions & 2 deletions test/demos/render.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React from "react";
import React, { StrictMode } from "react";
import { createRoot } from "react-dom/client";

export function render(Demo) {
return () => {
const container = document.createElement("div");
const root = createRoot(container);
root.render(<Demo />);
root.render(
<StrictMode>
<Demo />
</StrictMode>
);
return container;
};
}

0 comments on commit f3f8e87

Please sign in to comment.