mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00
modularize renderer (#552)
This commit is contained in:
parent
ac00bc98c0
commit
a86d4cbc58
15 changed files with 580 additions and 455 deletions
|
@ -0,0 +1,13 @@
|
|||
import equal from 'fast-deep-equal'
|
||||
import { RefObject, useEffect, useRef } from 'react'
|
||||
import { TocAst } from '../../../external-types/markdown-it-toc-done-right/interface'
|
||||
|
||||
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)
|
||||
}
|
||||
}, [onTocChange, tocAst])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue