I have a big application that I'm building with Next.js for SEO and performance purposes, and there's a super interactive part of this application that needs a Text Editor (such as Quill.js or Draft.js) where data in it is synced between two users using Socket.io.
The problem is I can't get a Text Editor to work with Next.js.
When I import Quill, it says 'Document is not defined' because there's no document on the server. With Draft.js, it simply doesn't render anything but there's no errors.
Here's my code for Draft.js:
import { EditorState, convertToRaw, convertFromRaw } from 'draft-js'
class TextEditor extends Component {
constructor(props) {
super(props);
this.state = {
editorState: EditorState.createWithContent(convertFromRaw(props.contentState))
}
}
static async getInitialProps ({ query, req }) {
return { contentState: convertToRaw(EditorState.createEmpty().getCurrentContent()) }
}
render() {
console.log('init',this.props.editorState);
return (
<div>
<h1>Test Editor</h1>
<Editor
editorState={ this.props.editorState }
/>
</div>
);
}
}
Any help?