mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-19 21:01:57 +02:00
Do not needlessly JSON.stringify() the whole editor (#4411)
* Do not needlessly JSON.stringify() the whole editor * Refactor based on feedback * Linting fix for error messages * linting fix Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
This commit is contained in:
parent
3e4d92005a
commit
62d1a068be
@ -1,7 +1,5 @@
|
||||
import React, { useMemo, useState, useCallback, useEffect } from 'react'
|
||||
import { Editor, Node, Element, Descendant } from 'slate'
|
||||
import invariant from 'tiny-invariant'
|
||||
|
||||
import { ReactEditor } from '../plugin/react-editor'
|
||||
import { FocusedContext } from '../hooks/use-focused'
|
||||
import { EditorContext } from '../hooks/use-slate-static'
|
||||
@ -23,17 +21,17 @@ export const Slate = (props: {
|
||||
const { editor, children, onChange, value, ...rest } = props
|
||||
const [key, setKey] = useState(0)
|
||||
const context: [ReactEditor] = useMemo(() => {
|
||||
invariant(
|
||||
Node.isNodeList(value),
|
||||
`[Slate] value is invalid! Expected a list of elements but got: ${JSON.stringify(
|
||||
value
|
||||
)}`
|
||||
)
|
||||
invariant(
|
||||
Editor.isEditor(editor),
|
||||
`[Slate] editor is invalid! you passed: ${JSON.stringify(editor)}`
|
||||
)
|
||||
|
||||
if (!Node.isNodeList(value)) {
|
||||
throw new Error(
|
||||
`[Slate] value is invalid! Expected a list of elements` +
|
||||
`but got: ${JSON.stringify(value)}`
|
||||
)
|
||||
}
|
||||
if (!Editor.isEditor(editor)) {
|
||||
throw new Error(
|
||||
`[Slate] editor is invalid! you passed:` + `${JSON.stringify(editor)}`
|
||||
)
|
||||
}
|
||||
editor.children = value
|
||||
Object.assign(editor, rest)
|
||||
return [editor]
|
||||
|
Loading…
x
Reference in New Issue
Block a user