react-native-draftjs-display
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

react-native-draftjs-display

CI CodeFactor

React Native component to display Draft.js content.

Partly forked from jdponomarev/react-native-draftjs-render, with the original code coming from globocom/react-native-draftjs-render. Re-written to use TypeScript, and to better fit in with my use-case.

It's quite barebones as I'm only adding functionality I need. Feel free to use this as an example for your own library, and I will review and accept any PRs.

Usage

// Directly from my own codebase
const TextBlockHandler = ({block}: {block: DraftContentBlock}) => (
  <DraftText block={block} TextComponent={Text} />
);
<>
  {data.getPost?.content && (
    <DraftDisplay
      contentState={JSON.parse(data.getPost.content)}
      blockHandlers={{
        atomic: ({block}) => <PostMediaBlock block={block} />, // blockHandlers are optional, I use this for images, audio and video clips
        'header-one': TextBlockHandler, // I should probably add a TextComponent prop to the context. TODO?
        'header-two': TextBlockHandler,
        'header-three': TextBlockHandler,
        'header-four': TextBlockHandler,
        'header-five': TextBlockHandler,
        'header-six': TextBlockHandler,
        paragraph: TextBlockHandler,
        unstyled: TextBlockHandler,
      }}
    />
  )}
</>

Development

Clone this repository and install its dependencies:

git clone https://github.com/lukeramsden/react-native-draftjs-display
cd react-native-draftjs-display
yarn # or npm install, if you're so inclined 

yarn run build builds the library to dist.

yarn test builds the library, then tests it.

License

ISC.

Readme

Keywords

none

Package Sidebar

Install

npm i react-native-draftjs-display

Weekly Downloads

1

Version

2.0.0

License

SEE LICENSE IN LICENSE

Unpacked Size

21.1 kB

Total Files

19

Last publish

Collaborators

  • lukeramsden