Reputation: 4962
I use draft-js-plugins. I used the emoji and the mention plugins together in my Editor. When I am using ,
convertToRaw(contentState)
to save my content data into the db, it shows an error message.
immutable.js:1421 Uncaught TypeError: Cannot read property 'entries' of undefined
But this error only comes when I have used mention in my content. it works fine with plain text and emojis contents. Please help.
Upvotes: 1
Views: 2666
Reputation: 4962
After working with this for a several time I found the reason. Here I am trying to save an immutable content into the DB. And trying to pass that data to the back-end via an Ajax call.
When we post data via an ajax call, we have to use JSON.stringify
and application/json; charset=utf-8
as follows.
$.ajax({
url: '/calendar/event/add',
method: "POST",
dataType: "JSON",
data: JSON.stringify(postData),
contentType: "application/json; charset=utf-8",
}).done(function (data, text) {
if(data.status.code == 200){
console.log("Success");
}
}.bind(this));
Upvotes: 0
Reputation: 687
Are you using draft-js plugins editor? It works fine for me, although I got confused between editorState
and contentState
in the beginning. These kind of errors pop up when I try to do convertToRaw(editorState)
make sure you are doing something like this:
_onChange (editorState) {
this.setState({
editorState,
});
const contentState = editorState.getCurrentContent();
console.log(convertToRaw(contentState));
}
Upvotes: 7