Unverified Commit 7013a8c2 authored by Henrik Wenz's avatar Henrik Wenz Committed by GitHub

[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: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent 46d3f0e2
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
}, },
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "^17.0.2", "react": "^18.0.0",
"react-dom": "^17.0.2", "react-dom": "^18.0.0",
"slate": "^0.58.4", "slate": "^0.76.1",
"slate-history": "0.58.4", "slate-history": "0.66.0",
"slate-react": "^0.58.4" "slate-react": "^0.76.1"
} }
} }
import React, { useState, useMemo } from 'react' import { useState } from 'react'
import { createEditor } from 'slate' import { createEditor } from 'slate'
import { Slate, Editable, withReact } from 'slate-react' import { Slate, Editable, withReact } from 'slate-react'
import { withHistory } from 'slate-history' import { withHistory } from 'slate-history'
const IndexPage = () => { export default function IndexPage() {
const [value, setValue] = useState(initialValue) const [editor] = useState(() => withReact(withHistory(createEditor())), [])
const editor = useMemo(() => withHistory(withReact(createEditor())), []) const [value, setValue] = useState([
{
children: [
{ text: 'This is editable plain text, just like a <textarea>!' },
],
},
])
return ( return (
<Slate editor={editor} value={value} onChange={(value) => setValue(value)}> <Slate editor={editor} value={value} onChange={setValue}>
<Editable placeholder="Enter some plain text..." /> <Editable placeholder="Enter some plain text..." />
</Slate> </Slate>
) )
} }
const initialValue = [
{
children: [
{ text: 'This is editable plain text, just like a <textarea>!' },
],
},
]
export default IndexPage
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment