render tiptap in react

This commit is contained in:
Philipp Kühn
2020-04-16 20:03:15 +02:00
parent 0676d67dbf
commit fa1c61ebbc
3 changed files with 31 additions and 31 deletions

View File

@@ -1,7 +1,11 @@
import Document from '@tiptap/extension-document' import Document from '@tiptap/extension-document'
import History from '@tiptap/extension-history'
import Paragraph from '@tiptap/extension-paragraph' import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text' import Text from '@tiptap/extension-text'
import History from '@tiptap/extension-history'
import Bold from '@tiptap/extension-bold'
import Italic from '@tiptap/extension-italic'
import Code from '@tiptap/extension-code'
import CodeBlock from '@tiptap/extension-codeblock'
export default function extensions() { export default function extensions() {
return [ return [
@@ -9,5 +13,9 @@ export default function extensions() {
new History(), new History(),
new Paragraph(), new Paragraph(),
new Text(), new Text(),
new Bold(),
new Italic(),
new Code(),
new CodeBlock(),
] ]
} }

View File

@@ -15,6 +15,10 @@
"@tiptap/extension-document": "1.x", "@tiptap/extension-document": "1.x",
"@tiptap/extension-history": "1.x", "@tiptap/extension-history": "1.x",
"@tiptap/extension-paragraph": "1.x", "@tiptap/extension-paragraph": "1.x",
"@tiptap/extension-text": "1.x" "@tiptap/extension-text": "1.x",
"@tiptap/extension-bold": "1.x",
"@tiptap/extension-italic": "1.x",
"@tiptap/extension-code": "1.x",
"@tiptap/extension-codeblock": "1.x"
} }
} }

View File

@@ -1,38 +1,26 @@
import React, { Component } from 'react'; import React, { Component } from 'react'
import { Editor } from '@tiptap/core'
import extensions from '@tiptap/starter-kit'
class Form extends Component { export default class TestComponent extends Component {
constructor() { constructor() {
super(); super()
this.editorNode = React.createRef()
this.state = {
value: ""
};
this.handleChange = this.handleChange.bind(this);
} }
handleChange(event) { componentDidMount() {
const { value } = event.target; this.editor = new Editor({
this.setState(() => { element: this.editorNode.current,
return { content: '<p>this is rendered in react</p>',
value extensions: extensions(),
}; })
});
} }
render() { render() {
return ( return (
<form> <div>
<input <div ref={this.editorNode} />
type="text" </div>
value={this.state.value} )
onChange={this.handleChange}
/>
<br/>
value: {this.state.value}
</form>
);
} }
} }
export default Form;