fix widget hook initial state
This commit is contained in:
parent
23bf60e3d0
commit
41c8da0177
@ -1,5 +1,5 @@
|
||||
import { Box } from "@mui/material";
|
||||
import { startTransition, useEffect, useRef, useState } from "react";
|
||||
import { startTransition, useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import { QuizIdContext } from "@contexts/QuizIdContext";
|
||||
import { RootContainerWidthContext } from "@contexts/RootContainerWidthContext";
|
||||
import QuizAnswerer from "../lib/components/QuizAnswerer";
|
||||
@ -13,6 +13,10 @@ export default function WidgetApp({ quizId }: Props) {
|
||||
const [rootContainerSize, setRootContainerSize] = useState<number>(() => window.innerWidth);
|
||||
const rootContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (rootContainerRef.current) setRootContainerSize(rootContainerRef.current.clientWidth);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const handleWindowResize = () => {
|
||||
startTransition(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user