slate-mentions
slate-mentions copied to clipboard
Make it possible to serialize editor state automatically
Rather than manually adding serialization rules for this plugin users can now do this:
import { Html } from 'slate';
import MentionPlugin from 'slate-mentions';
// Create the plugin as usual
const mentions = MentionPlugin({
Mention: MentionComponent,
Suggestions: SuggestionsComponent,
});
const { serialize } = new Html({
// Add the mentions serialization rules after any of your custom ones
rules: [...mentions.serializationRules]
});
// Get your current editor state as HTML 🎉
serialize(editor.state);
// You can also get your current editor state as React components:
serialize(editor.state, { render: false });
The serialize-to-react-component
-thing seems like a much better option for rendering messages, rather than rendering thousands of read-only editors. Am I right in assuming that's a better approach @ianstormtaylor?
I'm unsure if this actually makes sense, given that when you render a serialized mention you might want to render e.g. a link and not just a span. Might have to rethink this...