Skip to content

Commit

Permalink
Fix performance issue with renderPlaceholder
Browse files Browse the repository at this point in the history
  • Loading branch information
12joan committed Mar 6, 2023
1 parent 4ab18e8 commit 33b6352
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/small-timers-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Fixes #5335. To prevent performance issues, make sure to wrap custom `renderPlaceholder` values in `useCallback`.
6 changes: 5 additions & 1 deletion packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export type EditableProps = {
*/

export const Editable = (props: EditableProps) => {
const defaultRenderPlaceholder = useCallback(
(props: RenderPlaceholderProps) => <DefaultPlaceholder {...props} />,
[]
)
const {
autoFocus,
decorate = defaultDecorate,
Expand All @@ -137,7 +141,7 @@ export const Editable = (props: EditableProps) => {
readOnly = false,
renderElement,
renderLeaf,
renderPlaceholder = props => <DefaultPlaceholder {...props} />,
renderPlaceholder = defaultRenderPlaceholder,
scrollSelectionIntoView = defaultScrollSelectionIntoView,
style: userStyle = {},
as: Component = 'div',
Expand Down

0 comments on commit 33b6352

Please sign in to comment.