pell icon indicating copy to clipboard operation
pell copied to clipboard

Update React example to use React.createRef

Open kamerontanseli opened this issue 7 years ago • 2 comments

import 'pell/dist/pell.css'
import React, { Component } from 'react';
import { init } from 'pell';

export default class App extends Component {
  state = { html: null }
  root = React.createRef()

  componentDidMount () {
    this.editor = init({
      element: this.root.current,
      onChange: html => this.setState({ html }),
      actions: ['bold', 'underline', 'italic'],
    })
  }

  render() {
    return (
      <div className="App">
        <h3>Editor:</h3>
        <div ref={this.root} className="pell" />
        <h3>HTML Output:</h3>
        <div>{this.state.html}</div>
      </div>
    );
  }
}

kamerontanseli avatar Oct 25 '18 09:10 kamerontanseli

Why?

jaredreich avatar Oct 25 '18 15:10 jaredreich

element: document.getElementById('editor') Is not bound to the instance of the component. So one would not be able to have 2 App Components on the page.

kamerontanseli avatar Oct 25 '18 15:10 kamerontanseli