mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 18:56:32 -05:00
fix: use callback hook in checkbox editor component to cache function
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
37e1482c46
commit
7f20da0510
1 changed files with 18 additions and 11 deletions
|
@ -10,22 +10,29 @@ import type { TaskCheckedEventPayload } from './event-emitting-task-list-checkbo
|
|||
import { findCheckBox } from './find-check-box'
|
||||
import { TaskListCheckboxAppExtension } from './task-list-checkbox-app-extension'
|
||||
import type React from 'react'
|
||||
import { useCallback } from 'react'
|
||||
|
||||
/**
|
||||
* Receives task-checkbox-change events and modify the current editor content.
|
||||
*/
|
||||
export const SetCheckboxInCheatsheet: React.FC<CheatsheetExtensionComponentProps> = ({ setContent }) => {
|
||||
useExtensionEventEmitterHandler(TaskListCheckboxAppExtension.EVENT_NAME, (event: TaskCheckedEventPayload) => {
|
||||
setContent((previousContent) => {
|
||||
return findCheckBox(previousContent, event.lineInMarkdown)
|
||||
.map(
|
||||
([startIndex, endIndex]) =>
|
||||
previousContent.slice(0, startIndex) +
|
||||
createCheckboxContent(event.newCheckedState) +
|
||||
previousContent.slice(endIndex)
|
||||
useExtensionEventEmitterHandler(
|
||||
TaskListCheckboxAppExtension.EVENT_NAME,
|
||||
useCallback(
|
||||
(event: TaskCheckedEventPayload) => {
|
||||
setContent((previousContent) =>
|
||||
findCheckBox(previousContent, event.lineInMarkdown)
|
||||
.map(
|
||||
([startIndex, endIndex]) =>
|
||||
previousContent.slice(0, startIndex) +
|
||||
createCheckboxContent(event.newCheckedState) +
|
||||
previousContent.slice(endIndex)
|
||||
)
|
||||
.orElse(previousContent)
|
||||
)
|
||||
.orElse(previousContent)
|
||||
})
|
||||
})
|
||||
},
|
||||
[setContent]
|
||||
)
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue