mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 10:29:48 +02:00
Replace useMemo with useState in the docs (#5022)
* Replace useMemo with useState * Fix formatting
This commit is contained in:
@@ -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 <Slate editor={editor} value={initialValue} />
|
||||
}
|
||||
@@ -94,7 +94,7 @@ Okay, so the next step is to render the `<Editable>` component itself:
|
||||
const initialValue = []
|
||||
|
||||
const App = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
return (
|
||||
// Add the editable component inside the context.
|
||||
<Slate editor={editor} value={initialValue}>
|
||||
@@ -120,7 +120,7 @@ const initialValue = [
|
||||
]
|
||||
|
||||
const App = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
|
||||
return (
|
||||
<Slate editor={editor} value={initialValue}>
|
||||
|
@@ -17,7 +17,7 @@ const initialValue = [
|
||||
]
|
||||
|
||||
const App = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
|
||||
return (
|
||||
<Slate editor={editor} value={initialValue}>
|
||||
@@ -38,7 +38,7 @@ const initialValue = [
|
||||
]
|
||||
|
||||
const App = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
|
||||
return (
|
||||
<Slate editor={editor} value={initialValue}>
|
||||
@@ -68,7 +68,7 @@ const initialValue = [
|
||||
]
|
||||
|
||||
const App = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
|
||||
return (
|
||||
<Slate editor={editor} value={initialValue}>
|
||||
|
@@ -15,7 +15,7 @@ const initialValue = [
|
||||
]
|
||||
|
||||
const App = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
|
||||
return (
|
||||
<Slate editor={editor} value={initialValue}>
|
||||
@@ -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) {
|
||||
|
@@ -24,7 +24,7 @@ const initialValue = [
|
||||
]
|
||||
|
||||
const App = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
|
||||
return (
|
||||
<Slate editor={editor} value={initialValue}>
|
||||
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
@@ -15,7 +15,7 @@ const initialValue = [
|
||||
]
|
||||
|
||||
const App = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
|
||||
return (
|
||||
<Slate editor={editor} value={initialValue}>
|
||||
@@ -40,7 +40,7 @@ const initialValue = [
|
||||
]
|
||||
|
||||
const App = () => {
|
||||
const editor = useMemo(() => withReact(createEditor()), [])
|
||||
const [editor] = useState(() => withReact(createEditor()))
|
||||
|
||||
return (
|
||||
<Slate
|
||||
@@ -69,7 +69,7 @@ But... if you refresh the page, everything is still reset. That's because we nee
|
||||
|
||||
```jsx
|
||||
const App = () => {
|
||||
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')) || '',
|
||||
|
Reference in New Issue
Block a user