Skip to content
Discussion options

You must be logged in to vote

Here's how I would do that:

// This component should be rendered inside a PlateProvider,
// or else `editor` should be accessed another way
export default () => {
  const editor = usePlateEditorState();

  const selectionValue = useMemo(() => selection
    ? getEditorString(editor, editor.selection)
    : 'No selection'
  ), [editor, editor.selection]);

  return <textarea value={selectionValue} readOnly />;
};

You'll need to wrap the relevant parts of your application inside a PlateProvider in order for usePlateEditorState to work. If wrapping in a PlateProvider isn't practical, you can try one of the other ways of getting access to the editor described here.

Alternatively, you could acc…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@wenyongqd
Comment options

Comment options

You must be logged in to vote
1 reply
@wenyongqd
Comment options

Answer selected by 12joan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants