Skip to content

Commit

Permalink
fix: avoid requesting the same resource at first rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
SyLi9527 committed May 7, 2023
1 parent f2c3185 commit e3f51e5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Molstar.jsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 () => {
Expand All @@ -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);
})();
Expand Down

0 comments on commit e3f51e5

Please sign in to comment.