From e3f51e54235df6f3ba9b6b606d5097ff954e4107 Mon Sep 17 00:00:00 2001 From: SyLi9527 <79486258+SyLi9527@users.noreply.github.com> Date: Sun, 7 May 2023 21:18:12 +0200 Subject: [PATCH] fix: avoid requesting the same resource at first rendering --- src/Molstar.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Molstar.jsx b/src/Molstar.jsx index c1875a6..740b158 100644 --- a/src/Molstar.jsx +++ b/src/Molstar.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useRef } from "react"; +import React, { useEffect, useRef, useState } from "react"; import PropTypes from "prop-types"; import { DefaultPluginSpec } from "molstar/lib/mol-plugin/spec"; import { DefaultPluginUISpec } from "molstar/lib/mol-plugin-ui/spec"; @@ -14,7 +14,7 @@ const Molstar = props => { const parentRef = useRef(null); const canvasRef = useRef(null); const plugin = useRef(null); - + const [initialized, setInitialized] = useState(false); useEffect(() => { (async () => { @@ -39,12 +39,14 @@ const Molstar = props => { } } } }); } await loadStructure(pdbId, url, file, plugin.current); + setInitialized(true); })(); return () => plugin.current = null; }, []) useEffect(() => { + if (!initialized) return; (async() => { await loadStructure(pdbId, url, file, plugin.current); })();