Merge pull request #1452 from YousefED/patch-2

use forwardRef for react wrappers
This commit is contained in:
Philipp Kühn 2021-06-14 16:02:45 +02:00 committed by GitHub
commit 55203d38eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 28 deletions

View File

@ -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',
}}
/>
)
})

View File

@ -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',
}}
/>
)
})