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