Skip to content

Commit

Permalink
Remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Apr 22, 2022
1 parent 579b8aa commit e8d2841
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions packages/docusaurus-theme-common/src/hooks/useCodeWordWrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(false);
const codeBlock = useRef() as MutableRefObject<HTMLPreElement>;
Expand Down Expand Up @@ -49,8 +48,6 @@ export function useCodeWordWrap() {
}, [isEnabled, updateCodeIsScrollable]);

useEffect(() => {
updateCodeIsScrollable();

window.addEventListener('resize', updateCodeIsScrollable, {
passive: true,
});
Expand Down

0 comments on commit e8d2841

Please sign in to comment.