Guest User

Untitled

a guest
Jan 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import { Formik } from "formik";
  3. import FormField from "./FormField";
  4. import {
  5. EditorState,
  6. convertToRaw,
  7. convertFromRaw
  8. } from "draft-js";
  9.  
  10. export default class Draft extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. editorState: new EditorState.createEmpty(),
  15. };
  16. }
  17. handleSubmit = (values, { resetForm }) => {
  18. const rawContentState = convertToRaw(
  19. values.editorState.getCurrentContent()
  20. );
  21. const editorState = EditorState.createWithContent(
  22. convertFromRaw(rawContentState)
  23. );
  24. this.setState({
  25. editorState,
  26. });
  27. console.log(JSON.stringify(rawContentState, null, 2));
  28. resetForm({
  29. editorState: new EditorState.createEmpty(),
  30. });
  31. };
  32. render() {
  33. var { editorState } = this.state;
  34. return (
  35. <div>
  36. <Formik
  37. initialValues={{ editorState }}
  38. onSubmit={this.handleSubmit}
  39. >
  40. {props => <FormField {...props} />}
  41. </Formik>
  42. </div>
  43. );
  44. }
  45. }
Add Comment
Please, Sign In to add comment