mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-28 17:39:57 +02:00
Replace useMemo with useState in the docs (#5022)
* Replace useMemo with useState * Fix formatting
This commit is contained in:
@@ -13,7 +13,7 @@ import { createEditor } from 'slate'
|
||||
import { Slate, Editable, withReact } from 'slate-react'
|
||||
|
||||
const MyEditor = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
const renderElement = useCallback(({ attributes, children, element }) => {
|
||||
switch (element.type) {
|
||||
case 'quote':
|
||||
@@ -115,7 +115,7 @@ A common use case for this is rendering a toolbar with formatting buttons that a
|
||||
|
||||
```jsx
|
||||
const MyEditor = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
return (
|
||||
<Slate editor={editor}>
|
||||
<Toolbar />
|
||||
|
@@ -38,7 +38,7 @@ declare module 'slate' {
|
||||
Annotate the editor's initial value w/ `Descendant[]`.
|
||||
|
||||
```tsx
|
||||
import React, { useMemo, useState } from 'react'
|
||||
import React, { useState, useState } from 'react'
|
||||
import { createEditor, Descendant } from 'slate'
|
||||
import { Slate, Editable, withReact } from 'slate-react'
|
||||
|
||||
@@ -50,7 +50,7 @@ const initialValue: Descendant[] = [
|
||||
]
|
||||
|
||||
const App = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
|
||||
return (
|
||||
<Slate editor={editor} value={initialValue}>
|
||||
|
Reference in New Issue
Block a user