Skip to content

Commit

Permalink
Turn WordCount into a functional component (WordPress#24850)
Browse files Browse the repository at this point in the history
Replace `withSelect` HOC with `useSelect` hook to turn `WordCount` into a truly functional component.
  • Loading branch information
david-szabo97 authored Aug 27, 2020
1 parent b63cfef commit 817976a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/editor/src/components/word-count/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { useSelect } from '@wordpress/data';
import { _x } from '@wordpress/i18n';
import { count as wordCount } from '@wordpress/wordcount';

function WordCount( { content } ) {
export default function WordCount() {
const content = useSelect( ( select ) =>
select( 'core/editor' ).getEditedPostAttribute( 'content' )
);

/*
* translators: If your word count is based on single characters (e.g. East Asian characters),
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
Expand All @@ -19,9 +23,3 @@ function WordCount( { content } ) {
</span>
);
}

export default withSelect( ( select ) => {
return {
content: select( 'core/editor' ).getEditedPostAttribute( 'content' ),
};
} )( WordCount );

0 comments on commit 817976a

Please sign in to comment.