Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 <22380829+ijjk@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
17 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
import React, { useState, useMemo } from 'react' | ||
import { useState } from 'react' | ||
import { createEditor } from 'slate' | ||
import { Slate, Editable, withReact } from 'slate-react' | ||
import { withHistory } from 'slate-history' | ||
|
||
const IndexPage = () => { | ||
const [value, setValue] = useState(initialValue) | ||
const editor = useMemo(() => withHistory(withReact(createEditor())), []) | ||
export default function IndexPage() { | ||
const [editor] = useState(() => withReact(withHistory(createEditor())), []) | ||
const [value, setValue] = useState([ | ||
{ | ||
children: [ | ||
{ text: 'This is editable plain text, just like a <textarea>!' }, | ||
], | ||
}, | ||
]) | ||
|
||
return ( | ||
<Slate editor={editor} value={value} onChange={(value) => setValue(value)}> | ||
<Slate editor={editor} value={value} onChange={setValue}> | ||
<Editable placeholder="Enter some plain text..." /> | ||
</Slate> | ||
) | ||
} | ||
|
||
const initialValue = [ | ||
{ | ||
children: [ | ||
{ text: 'This is editable plain text, just like a <textarea>!' }, | ||
], | ||
}, | ||
] | ||
|
||
export default IndexPage |