Skip to content

Commit

Permalink
Merge pull request ueberdosis#1452 from YousefED/patch-2
Browse files Browse the repository at this point in the history
use forwardRef for react wrappers
  • Loading branch information
philippkuehn authored Jun 14, 2021
2 parents d93695a + 8b1c610 commit 50ffb43
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
29 changes: 16 additions & 13 deletions src/NodeViewContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ export interface NodeViewContentProps {
as?: React.ElementType,
}

export const NodeViewContent: React.FC<NodeViewContentProps> = props => {
const Tag = props.as || 'div'
export const NodeViewContent: React.FC<NodeViewContentProps> =
React.forwardRef((props, ref) => {
const Tag = props.as || 'div'

return (
<Tag
{...props}
data-node-view-content=""
style={{
...props.style,
whiteSpace: 'pre-wrap',
}}
/>
)
}
return (
<Tag
{...props}
ref={ref}
data-node-view-content=""
style={{
...props.style,
whiteSpace: 'pre-wrap',
}}
/>
)
})

32 changes: 17 additions & 15 deletions src/NodeViewWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ export interface NodeViewWrapperProps {
as?: React.ElementType,
}

export const NodeViewWrapper: React.FC<NodeViewWrapperProps> = props => {
const { onDragStart } = useReactNodeView()
const Tag = props.as || 'div'
export const NodeViewWrapper: React.FC<NodeViewWrapperProps> =
React.forwardRef((props, ref) => {
const { onDragStart } = useReactNodeView()
const Tag = props.as || 'div'

return (
<Tag
{...props}
data-node-view-wrapper=""
onDragStart={onDragStart}
style={{
...props.style,
whiteSpace: 'normal',
}}
/>
)
}
return (
<Tag
{...props}
ref={ref}
data-node-view-wrapper=""
onDragStart={onDragStart}
style={{
...props.style,
whiteSpace: 'normal',
}}
/>
)
})

0 comments on commit 50ffb43

Please sign in to comment.