Fix some bugs

This commit is contained in:
2023-07-21 15:42:11 +09:00
parent 3107f4de80
commit 3c8ac297b2
3 changed files with 6 additions and 9 deletions

View File

@ -13,10 +13,7 @@ export const ExcalidrawMain = () => {
const [toggleState, setToggleState] = useState<boolean>(false); const [toggleState, setToggleState] = useState<boolean>(false);
const onClose = useCallback( const onClose = useCallback(() => setToggleState(false), []);
() => setToggleState(!toggleState),
[toggleState]
);
return ( return (
<ExcalidrawContainer <ExcalidrawContainer

View File

@ -3,7 +3,7 @@ import type {
ExcalidrawProps, ExcalidrawProps,
ExcalidrawImperativeAPI, ExcalidrawImperativeAPI,
} from '@excalidraw/excalidraw/types/types'; } from '@excalidraw/excalidraw/types/types';
import { FC, useCallback, useEffect, useMemo, useState } from 'react'; import { FC, useEffect, useMemo, useState } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
export type WindowRect = { export type WindowRect = {
@ -46,17 +46,17 @@ export const ExcalidrawContainer: FC<ExcalidrawContainerProps> = (props) => {
height: window.innerHeight, height: window.innerHeight,
}); });
const onResize = useCallback(() => { const onResize = () => {
setWindowRect({ setWindowRect({
width: window.innerWidth, width: window.innerWidth,
height: window.innerHeight, height: window.innerHeight,
}); });
}, []); };
useEffect(() => { useEffect(() => {
window.addEventListener('resize', onResize); window.addEventListener('resize', onResize);
return () => window.removeEventListener('resize', onResize); return () => window.removeEventListener('resize', onResize);
}, [onResize]); }, []);
return ( return (
<ExcalidrawBox $scale={scale} $windowRect={windowRect}> <ExcalidrawBox $scale={scale} $windowRect={windowRect}>

View File

@ -21,7 +21,7 @@ const RightTopUI: FC<RightTopUIProps> = (props) => {
const sidebarToggle = useCallback( const sidebarToggle = useCallback(
(variant: SidebarVariant) => { (variant: SidebarVariant) => {
if (excalidrawAPI && !props.toggleState) { if (excalidrawAPI && !props.toggleState) {
props.setToggleState(props.toggleState); props.setToggleState(true);
props.setSidebarVariant(variant); props.setSidebarVariant(variant);
excalidrawAPI.toggleMenu('customSidebar'); excalidrawAPI.toggleMenu('customSidebar');
} }