diff --git a/docs/concepts/09-rendering.md b/docs/concepts/09-rendering.md index 6d6a60056..fd5d4bcbe 100644 --- a/docs/concepts/09-rendering.md +++ b/docs/concepts/09-rendering.md @@ -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 ( diff --git a/docs/concepts/12-typescript.md b/docs/concepts/12-typescript.md index de276a8bc..a7e6b702b 100644 --- a/docs/concepts/12-typescript.md +++ b/docs/concepts/12-typescript.md @@ -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 ( diff --git a/docs/libraries/slate-history.md b/docs/libraries/slate-history.md index 71edaedef..8736948b6 100644 --- a/docs/libraries/slate-history.md +++ b/docs/libraries/slate-history.md @@ -17,5 +17,5 @@ The `withHistory` plugin keeps track of the operation history of a Slate editor When used with `withReact`, `withHistory` should be applied inside. For example: ```javascript -const editor = useMemo(() => withReact(withHistory(createEditor())), []) +const [editor] = useState(() => withReact(withHistory(createEditor()))) ``` diff --git a/docs/libraries/slate-react.md b/docs/libraries/slate-react.md index 5cdbbf91a..3945d3d7a 100644 --- a/docs/libraries/slate-react.md +++ b/docs/libraries/slate-react.md @@ -195,7 +195,7 @@ Adds React and DOM specific behaviors to the editor. When used with `withHistory`, `withReact` should be applied outside. For example: ```javascript -const editor = useMemo(() => withReact(withHistory(createEditor())), []) +const [editor] = useState(() => withReact(withHistory(createEditor()))) ``` ## Utils diff --git a/docs/walkthroughs/01-installing-slate.md b/docs/walkthroughs/01-installing-slate.md index 705f11a81..46aa9629b 100644 --- a/docs/walkthroughs/01-installing-slate.md +++ b/docs/walkthroughs/01-installing-slate.md @@ -18,7 +18,7 @@ Once you've installed Slate, you'll need to import it. ```jsx // Import React dependencies. -import React, { useMemo } from 'react' +import React, { useState } from 'react' // Import the Slate editor factory. import { createEditor } from 'slate' @@ -40,7 +40,7 @@ The next step is to create a new `Editor` object. We want the editor to be stabl ```jsx const App = () => { // Create a Slate editor object that won't change across renders. - const editor = useMemo(() => withReact(createEditor()), []) + const editor = useState(() => withReact(createEditor())) return null } ``` @@ -74,7 +74,7 @@ The provider component keeps track of your Slate editor, its plugins, its value, const initialValue = [] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) // Render the Slate context. return } @@ -94,7 +94,7 @@ Okay, so the next step is to render the `` component itself: const initialValue = [] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) return ( // Add the editable component inside the context. @@ -120,7 +120,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) return ( diff --git a/docs/walkthroughs/02-adding-event-handlers.md b/docs/walkthroughs/02-adding-event-handlers.md index 6ab214b43..254194539 100644 --- a/docs/walkthroughs/02-adding-event-handlers.md +++ b/docs/walkthroughs/02-adding-event-handlers.md @@ -17,7 +17,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) return ( @@ -38,7 +38,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) return ( @@ -68,7 +68,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) return ( diff --git a/docs/walkthroughs/03-defining-custom-elements.md b/docs/walkthroughs/03-defining-custom-elements.md index aad26742d..49b80bfe1 100644 --- a/docs/walkthroughs/03-defining-custom-elements.md +++ b/docs/walkthroughs/03-defining-custom-elements.md @@ -15,7 +15,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) return ( @@ -74,7 +74,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) // Define a rendering function based on the element passed to `props`. We use // `useCallback` here to memoize the function for subsequent renders. @@ -130,7 +130,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) const renderElement = useCallback(props => { switch (props.element.type) { @@ -188,7 +188,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) const renderElement = useCallback(props => { switch (props.element.type) { diff --git a/docs/walkthroughs/04-applying-custom-formatting.md b/docs/walkthroughs/04-applying-custom-formatting.md index 9d40d61e8..e2dd87a6c 100644 --- a/docs/walkthroughs/04-applying-custom-formatting.md +++ b/docs/walkthroughs/04-applying-custom-formatting.md @@ -24,7 +24,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) return ( @@ -60,7 +60,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) const renderElement = useCallback(props => { switch (props.element.type) { @@ -146,7 +146,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) const renderElement = useCallback(props => { switch (props.element.type) { diff --git a/docs/walkthroughs/05-executing-commands.md b/docs/walkthroughs/05-executing-commands.md index 9ff08029d..dbb1458fd 100644 --- a/docs/walkthroughs/05-executing-commands.md +++ b/docs/walkthroughs/05-executing-commands.md @@ -19,7 +19,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) const renderElement = useCallback(props => { switch (props.element.type) { @@ -126,7 +126,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) const renderElement = useCallback(props => { switch (props.element.type) { @@ -183,7 +183,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) const renderElement = useCallback(props => { switch (props.element.type) { diff --git a/docs/walkthroughs/06-saving-to-a-database.md b/docs/walkthroughs/06-saving-to-a-database.md index 208c7ff4e..1bd963227 100644 --- a/docs/walkthroughs/06-saving-to-a-database.md +++ b/docs/walkthroughs/06-saving-to-a-database.md @@ -15,7 +15,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) return ( @@ -40,7 +40,7 @@ const initialValue = [ ] const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) return ( { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) // Update the initial content to be pulled from Local Storage if it exists. const initialValue = useMemo( () => @@ -135,7 +135,7 @@ const deserialize = string => { } const App = () => { - const editor = useMemo(() => withReact(createEditor()), []) + const [editor] = useState(() => withReact(createEditor())) // Use our deserializing function to read the data from Local Storage. const initialValue = useMemo( deserialize(localStorage.getItem('content')) || '',