0.1.0 • Published 5 years ago

@draft-js-modules/editor v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@draft-js-modules/editor

Installation

# using npm:
npm install --save @draft-js-modules/editor

# using yarn:
yarn add @draft-js-modules/editor

Usage

import { Editor } from '@draft-js-modules/editor'
import { EditorState } from 'draft-js'
import 'draft-js/dist/Draft.css'
import React, { useCallback, useRef, useState } from 'react'

const modules = []

function DraftEditor() {
  const store = useRef(null)
  const [editorState, setEditorState] = useState(EditorState.createEmpty())

  const onClick = useCallback(() => {
    store.current.getEditor().focus()
  }, [])

  const onChange = useCallback(editorState => {
    setEditorState(editorState)
  }, [])

  return (
    <div onClick={onClick}>
      <Editor
        editorState={editorState}
        onChange={onChange}
        placeholder="Editor for Draft.js Modules"
        modules={modules}
        store={store}
      />
    </div>
  )
}

export default DraftEditor