draftjs-raw-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

draftjs-raw-parser

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install draftjs-raw-parser

or

yarn add draftjs-raw-parser

Usage

import React from 'react'
import { ParsedData } from 'draftjs-raw-parser'
import { convertToRaw, Editor, EditorState, RichUtils } from 'draft-js'

const App = () => {
  const [editorState, setEditorState] = React.useState(() =>
    EditorState.createEmpty()
  )

  const postRawContent = convertToRaw(editorState.getCurrentContent()).blocks
  console.log(postRawContent)

  const handleKeyCommand = (command: any, editorState: any) => {
    const newState = RichUtils.handleKeyCommand(editorState, command)

    if (newState) {
      setEditorState(newState)
      return 'handled'
    }

    return 'not-handled'
  }
  return (
    <Fragment>
      <Editor
        editorState={editorState}
        onChange={setEditorState}
        handleKeyCommand={handleKeyCommand}
        placeholder='Content'
      />
      {/* Parsed Data */}
      <div style={{ border: '1px solid' }}>
        <ParsedData
          rawContent={JSON.stringify(postRawContent)}
          color='#0066ff'
          fontSize='20px'
        />
      </div>
    </Fragment>
  )
}

export default App

License

MIT © aadityarajkumawat

Readme

Keywords

none

Package Sidebar

Install

npm i draftjs-raw-parser

Weekly Downloads

6

Version

1.0.6

License

MIT

Unpacked Size

57.8 kB

Total Files

27

Last publish

Collaborators

  • edydee