1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-12 18:24:03 +02:00

Make onChange prop optional, update examples and docs to treat slate as uncontrolled (#4922)

* Make onChange prop optional, update examples and docs to treat slate as uncontrolled

* Add changeset
This commit is contained in:
Eric Meier
2022-04-03 16:52:32 +01:00
committed by GitHub
parent 08d5a12c91
commit 9892cf0ffb
29 changed files with 207 additions and 246 deletions

View File

@@ -20,7 +20,7 @@ export const Slate = (props: {
editor: ReactEditor
value: Descendant[]
children: React.ReactNode
onChange: (value: Descendant[]) => void
onChange?: (value: Descendant[]) => void
}) => {
const { editor, children, onChange, value, ...rest } = props
const unmountRef = useRef(false)
@@ -48,7 +48,10 @@ export const Slate = (props: {
} = getSelectorContext(editor)
const onContextChange = useCallback(() => {
onChange(editor.children)
if (onChange) {
onChange(editor.children)
}
setContext([editor])
handleSelectorChange(editor)
}, [onChange])