New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@troop.com/tiptap-react-render

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@troop.com/tiptap-react-render

Render TipTap JSON in React without the editor!

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1K
decreased by-12.35%
Maintainers
1
Weekly downloads
 
Created
Source

TipTap React Render

npm npm

This library renders TipTap JSON payloads in React clients without embedding the editor.

Installation

# npm
npm install @troop.com/tiptap-react-render

# yarn
yarn add @troop.com/tiptap-react-render

Usage

// handle the document
const doc: NodeHandler = (props) => (<>{props.children}</>)

// handle a paragraph
const paragraph: NodeHandler = (props) => {
  return <p>{props.children}</p>
}

// handle text
const text: NodeHandler = (props) => {
  // you could process text marks here from props.node.marks ...
  return <span>{props.node.text}</span>
}

// handle an image
const img: NodeHandler = (props) => {
  const { src, alt, title } = props.node;
  return (<img src={src} alt={alt} title={title} />)
}

// create a handlers wrapper
const handlers: NodeHandlers = {
  "doc": doc,
  "text": text,
  "paragraph": paragraph,
  "img": img,
}

// sample tip tap data
const data = {
  type: "doc",
  content: [
    {
      type: "paragraph",
      content: [{
        type: "text",
        text: "hello world"
      }],
      type: "paragraph",
      content: [{
        type: "img",
        src: "https://some-url.com/img.jpg",
        alt: "some alt text"
      }]
    }
  ]
}

// render it!
const rendered = <TipTapRender handlers={handlers} node={data} />

Why?

Many folks render TipTap rich text by embedding the TipTap editor in a "read-only" mode. However, if you don't want to add TipTap as a dependency (or, like us, you're using a platform that can't support it like React Native), then this is a simple, lightweight tool for mapping TipTap nodes to presentation components!

We were inspired by Contentful's rich-text-react-renderer tool, so we built a similar one for TipTap payloads!

This repo was scaffolded using the @alexeagleson/template-react-component-library

FAQs

Package last updated on 12 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc