use ref to check if the value is set, because of SSR

we definitely need to find a better pattern, instead of resetting on every request, we should be creating a new container on every request
This commit is contained in:
Oleg Isonen committed 2022-08-04 19:43:49 +02:00
1 parent bec39641af
commit a88296205b
1 file changed
+4 -2
+4 -2
View File
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo } from "react";
import { useCallback, useEffect, useMemo, useRef } from "react";
import ObjectId from "bson-objectid";
import {
type InstanceProps,
@@ -38,8 +38,10 @@ import {
import { useMeasure } from "~/shared/dom-hooks";
export const usePopulateRootInstance = (tree: Tree) => {
const ref = useRef(false);
// It is only set once when the canvas is first loaded.
if (rootInstanceContainer.value === undefined) {
if (ref.current === false) {
ref.current = true;
rootInstanceContainer.value = tree.root;
}
};