Skip to content

Commit

Permalink
Switch to a single hook
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinhenderson committed Aug 6, 2024
1 parent 51cf895 commit 502aa49
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions src/components/results.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
"use client";

import { useEffect, useState } from "react";
import { useEffect } from "react";
import { Model } from "survey-core";

export default function Results({ surveyData }) {
const [survey, setSurvey] = useState(null);
const [vizPanel, setVizPanel] = useState(null);

useEffect(() => {
(async () => {
const survey = new Model(surveyData.survey);
setSurvey(survey);

const { VisualizationPanel } = await import("survey-analytics");

Expand All @@ -21,24 +17,19 @@ export default function Results({ surveyData }) {
allowHideQuestions: false,
}
);
setVizPanel(currentPanel);

currentPanel.render("surveyVizPanel");

return () => {
const panelElement = document.getElementById("surveyVizPanel");

if (panelElement) {
panelElement.innerHTML = "";
}
};
})();
}, [surveyData]);

useEffect(() => {
if (vizPanel) {
vizPanel.render("surveyVizPanel");
}

return () => {
const panelElement = document.getElementById("surveyVizPanel");

if (panelElement) {
panelElement.innerHTML = "";
}
};
}, [vizPanel]);

return (
<div>
<div id="surveyVizPanel" />
Expand Down

0 comments on commit 502aa49

Please sign in to comment.