1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-28 09:29:49 +02:00

Proposal for Remove useCallback from walkthroughs documentation (#4091)

* Proposal for Remove useCallback from walkthroughs

I have seen in the walkthrough the use of `useCallback` but I don't think are need it, and add a small complexity while understanding the concept, if we moved out the function outside of the component will be stable and will not require to maintain either referential identity or calculated complex logic. 

If people think this is a good idea I can go and update all documentation to remove unnecessary `useCallback` from the example.

unless I'm missing something.

* Update docs/walkthroughs/04-applying-custom-formatting.md

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
This commit is contained in:
Ind. Puking Rainbows
2021-08-18 15:59:31 -07:00
committed by GitHub
parent 8e4120ae31
commit 2fa928103d

View File

@@ -7,6 +7,15 @@ In this guide, we'll show you how to add custom formatting options, like **bold*
So we start with our app from earlier:
```jsx
const renderElement = (props) => {
switch (props.element.type) {
case 'code':
return <CodeElement {...props} />
default:
return <DefaultElement {...props} />
}
})
const App = () => {
const editor = useMemo(() => withReact(createEditor()), [])
const [value, setValue] = useState([
@@ -16,15 +25,6 @@ const App = () => {
},
])
const renderElement = useCallback(props => {
switch (props.element.type) {
case 'code':
return <CodeElement {...props} />
default:
return <DefaultElement {...props} />
}
}, [])
return (
<Slate editor={editor} value={value} onChange={value => setValue(value)}>
<Editable