From e8d28417841a94ba0d638ad4bc18bebe7f60dd27 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Fri, 22 Apr 2022 13:23:35 +0300 Subject: [PATCH] Remove duplicate code --- .../src/hooks/useCodeWordWrap.ts | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/docusaurus-theme-common/src/hooks/useCodeWordWrap.ts b/packages/docusaurus-theme-common/src/hooks/useCodeWordWrap.ts index 9657fb5607ef..c80ecf5b032b 100644 --- a/packages/docusaurus-theme-common/src/hooks/useCodeWordWrap.ts +++ b/packages/docusaurus-theme-common/src/hooks/useCodeWordWrap.ts @@ -5,16 +5,15 @@ * LICENSE file in the root directory of this source tree. */ -import type { - MutableRefObject} from 'react'; -import { - useState, - useCallback, - useEffect, - useRef -} from 'react'; - -export function useCodeWordWrap() { +import type {MutableRefObject} from 'react'; +import {useState, useCallback, useEffect, useRef} from 'react'; + +export function useCodeWordWrap(): { + readonly codeBlockRef: (node: HTMLPreElement | null) => void; + readonly isEnabled: boolean; + readonly isCodeScrollable: boolean; + readonly toggle: () => void; +} { const [isEnabled, setIsEnabled] = useState(false); const [isCodeScrollable, setIsCodeScrollable] = useState(false); const codeBlock = useRef() as MutableRefObject; @@ -49,8 +48,6 @@ export function useCodeWordWrap() { }, [isEnabled, updateCodeIsScrollable]); useEffect(() => { - updateCodeIsScrollable(); - window.addEventListener('resize', updateCodeIsScrollable, { passive: true, });