Skip to content

Commit 7013a8c

Browse files
HaNdTriXijjk
andauthored
[example] Fix fast refresh in with-slate example (#36095)
This PR fixes #29740 and updates the with-slate example to match slates latest version. [more info](https://docs.slatejs.org/walkthroughs/01-installing-slate) ## Bug - [x] Related issues linked using `fixes #number` ## Documentation / Examples - [x] Make sure the linting passes by running `yarn lint` Co-authored-by: JJ Kasper <[email protected]>
1 parent 46d3f0e commit 7013a8c

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

examples/with-slate/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
},
88
"dependencies": {
99
"next": "latest",
10-
"react": "^17.0.2",
11-
"react-dom": "^17.0.2",
12-
"slate": "^0.58.4",
13-
"slate-history": "0.58.4",
14-
"slate-react": "^0.58.4"
10+
"react": "^18.0.0",
11+
"react-dom": "^18.0.0",
12+
"slate": "^0.76.1",
13+
"slate-history": "0.66.0",
14+
"slate-react": "^0.76.1"
1515
}
1616
}

examples/with-slate/pages/index.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
import React, { useState, useMemo } from 'react'
1+
import { useState } from 'react'
22
import { createEditor } from 'slate'
33
import { Slate, Editable, withReact } from 'slate-react'
44
import { withHistory } from 'slate-history'
55

6-
const IndexPage = () => {
7-
const [value, setValue] = useState(initialValue)
8-
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
6+
export default function IndexPage() {
7+
const [editor] = useState(() => withReact(withHistory(createEditor())), [])
8+
const [value, setValue] = useState([
9+
{
10+
children: [
11+
{ text: 'This is editable plain text, just like a <textarea>!' },
12+
],
13+
},
14+
])
15+
916
return (
10-
<Slate editor={editor} value={value} onChange={(value) => setValue(value)}>
17+
<Slate editor={editor} value={value} onChange={setValue}>
1118
<Editable placeholder="Enter some plain text..." />
1219
</Slate>
1320
)
1421
}
15-
16-
const initialValue = [
17-
{
18-
children: [
19-
{ text: 'This is editable plain text, just like a <textarea>!' },
20-
],
21-
},
22-
]
23-
24-
export default IndexPage

0 commit comments

Comments
 (0)