Skip to content

Instantly share code, notes, and snippets.

@ddelrio1986
Created November 8, 2017 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddelrio1986/30428183bb6b449033d7d23393beab34 to your computer and use it in GitHub Desktop.
Save ddelrio1986/30428183bb6b449033d7d23393beab34 to your computer and use it in GitHub Desktop.
DraftJS ContentState Logger
export const contentStateLogger = editorState => {
const result = JSON.stringify(convertToRaw(editorState.getCurrentContent()), null, 4);
const newResult = JSON.parse(result);
const contentState = JSON.stringify(newResult, null, 4);
// unquotes object keys
const keyQuotes = /"(.+)"(?=:)/g;
const newContentState = contentState.replace(keyQuotes, '$1');
console.log(newContentState);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment