Skip to content

Make editor.storage aware of changes for the character count plugin #5649

Discussion options

You must be logged in to vote
const CharacterCountPlugin = ({ editor }: { editor: Editor }) => {
  const { characterCount, wordCount } = useEditorState({
    editor,
    selector: ctx => {
      return {
        characterCount: ctx.editor.storage.characterCount.characters(),
        wordCount: ctx.editor.storage.characterCount.words(),
      }
    },
  })

  return (
    <>
      <Flex align="center" justify="center" gap="3">
        <Text color="gray" size="1">
          {characterCount} chars
        </Text>
        <Separator orientation="vertical" />
        <Text color="gray" size="1">
          {wordCount} words
        </Text>
      </Flex>
    </>
  );
};

Here is how you would pull the character count and word…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by nperez0111
Comment options

You must be logged in to vote
3 replies
@nperez0111
Comment options

@oluijks
Comment options

@nperez0111
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants