mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-04-27 10:20:37 +00:00
19 lines
619 B
TypeScript
19 lines
619 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import equal from 'fast-deep-equal'
|
|
import { TocAst } from 'markdown-it-toc-done-right'
|
|
import { RefObject, useEffect, useRef } from 'react'
|
|
|
|
export const usePostTocAstOnChange = (tocAst: RefObject<TocAst|undefined>, onTocChange?: (ast: TocAst) => void): void => {
|
|
const lastTocAst = useRef<TocAst>()
|
|
useEffect(() => {
|
|
if (onTocChange && tocAst.current && !equal(tocAst, lastTocAst.current)) {
|
|
lastTocAst.current = tocAst.current
|
|
onTocChange(tocAst.current)
|
|
}
|
|
})
|
|
}
|