• Operand
  • license? go ahead.

gram:page

> ./src/spine.tsx

Lenses
(coming soon!)


import { Component, createRef } from "react"
import {EditorView} from "prosemirror-view"

class Spine extends Component {
  constructor(props) {
    super(props)
    this.spine = createRef()
  }

  componentDidMount() {
    this.page = new EditorView(
      this.spine.current,
      { state: this.props.page }
    )
  }

  componentDidUpdate(priorProps, priorState) {
    if(page) this.page.updateState(page)
    else this.page && this.page.destroy()
  }

  componentWillUnmount = () => this.page && this.page.destroy()
  render = () => <div id="page" ref={this.spine}></div>
}

export default Spine