
Learn to build rich text editors in React with Draft.js, covering editor setup, content state, and bold and underline formatting. Save and display edited content in your app.
Draft.js is a React framework for building rich text editors, powered by an immutable model and open-sourced by Facebook. It renders on every keystroke and supports styling via toolbar buttons.
EditorState is an immutable, all-encompassing record that represents the entire editor state, including the current text content, the current selection, and the fully decorated contents with styles.
Explore how content state captures blocks and entity ranges as the editor's full contents in Draft.js. Learn how getCurrentContent retrieves content being rendered and its before and after selection states.
Explore how editor state and content state objects organize Draft.js content, including the editor contents and two selection states before and after rendering, and how they are used.
Create a new React app with create-react-app using Yarn, explore the generated folder structure, and run the development server with live reload to start coding right away.
Install draft.js for a React project using npm, add it to the project, and verify it in package.json, then prepare to use draft.js in the app.
Create a Draft.js editor in a React app by building an editor component, importing editor and editorState, and wiring an onChange handler. Render hello world and add rich style features.
Add rich text utilities to the editor by implementing a handle key command that uses a utility library to apply bold, italic, and underline through editor state updates.
Enhance rich text utilities in a React editor by adding buttons for bold, italic, underline, and code blocks, wiring them to a key command handler and supporting ctrl/command bindings.
Extract the editor's content state from the editor state, convert it to a raw representation, and display it as a pretty JSON string. Use a pre element for rendering.
Explore how Draft.js content state represents text: each paragraph is a block in the blocks array with a unique key, text, inline style ranges, and the entity map.
Learn to save and load rich text editor content in a React with Draft.js app using local storage, and optionally via a REST API to a database.
Learn to load saved editor content from local storage into a draft.js editor by deserializing raw data with convertFromRaw, converting to content state, and creating an editor state.
Learn to display saved Draft.js content as HTML by converting the editor's content state with a dedicated exporter, install the library, and render an HTML view alongside the editor.
Display saved contents as HTML in a React Draft.js editor using dangerouslySetInnerHTML. This approach is not recommended due to cross-site scripting risks and potential security exposure.
Use a read-only draft.js editor to display saved content as static text, loading content from local storage into an editor state and rendering it without edit controls.
Learn to implement rich text editing features in a React application using Draft.js, and check out the author's blog for tutorials on React and other web development topics.
In this course we will go through how to add rich text editing features (such as bold, underline, italic) to your React application, using an open source framework called Draft.js.
You will learn
How to add rich text editor component to your React application
How to add features like bold and underline to the editor
How to save rich text content to database
How to load rich text content from database
How to edit saved content
How to display saved rich text content e.g. as HTML
Prior knowledge of rich text editing and Draft.js is NOT required. Basic knowledge on React is however required because we will be concentrating on Draft.js features.