0

I have a form on my react app. I want to capture the input from the form from my users and store the text in a state property and then send the text back to my server. I have followed the basic DraftJS tutorial however it gives me a map in my state, instead of just the text needed to send back to the server.

 constructor(props) {
        super(props);
        this.state = {
            name: '',
            teamName: '',
            editorState: EditorState.createEmpty(),
            teamId: '',
            uploadedFileCloudinaryUrl: ''
        };
        this.handleChange = this.handleChange.bind(this);
        this.handleSubmit = this.handleSubmit.bind(this);
        this.onChange = (editorState) => this.setState({ editorState });
    }

<Editor editorState={this.state.editorState} onChange={this.onChange} />

Is there something special I have to do to get the text from the editor?

N P
  • 2,319
  • 7
  • 32
  • 54
  • Can you show how you are trying to send the text to the server? So far your code is only about capturing the state of the editor. – Deividas Feb 22 '17 at 14:02
  • I just create an object from the state of my form elements and then post the data, but my server will accept a string not a editor instance – N P Feb 22 '17 at 14:12

1 Answers1

1

It appears that you want to send an object to the server and your server only accepts strings. In that case you can use JSON.stringify. So to send the editor state to the server you would run sendToSeverFunction(JSON.stringify(this.props.editorState)) and then decode the string in your server.

Deividas
  • 6,437
  • 2
  • 26
  • 27