Skip to content
This repository was archived by the owner on May 31, 2020. It is now read-only.

forward ref #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/djs-editor/src/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import React from 'react'
import Draft from 'draft-js'
import { withConsumer } from './EditorContainer'

export default withConsumer(({ editorProps }) => <Draft.Editor {...editorProps}/>)
export default withConsumer(
React.forwardRef(({ editorProps }, ref) => <Draft.Editor {...editorProps} ref={ref} />)
)
8 changes: 5 additions & 3 deletions packages/djs-editor/src/EditorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const { CompositeDecorator, EditorState, getDefaultKeyBinding, DefaultDraftBlock

export const Context = createContext({})

export const withConsumer = Comp => props => (
<Context.Consumer>{contextProps => <Comp {...props} {...contextProps} />}</Context.Consumer>
)
export const withConsumer = Comp => React.forwardRef((props, ref) => (
<Context.Consumer>
{contextProps => <Comp {...props} {...contextProps} ref={ref} />}
</Context.Consumer>
))

const resolveDecorator = plugins => new CompositeDecorator(
Array.from(plugins.values()).reduce((acc, plugin) => (
Expand Down