UNPKG

@wordpress/editor

Version:
35 lines (30 loc) 1.05 kB
import { useSelect } from '@wordpress/data'; import PostTypeSupportCheck from '../post-type-support-check'; import { store as editorStore } from '../../store'; /** * Wrapper component that renders its children if the post has more than one revision. * * @param {Object} props Props. * @param {React.ReactNode} props.children Children to be rendered. * * @return {React.ReactNode} Rendered child components if post has more than one revision, otherwise null. */ function PostLastRevisionCheck( { children } ) { const { lastRevisionId, revisionsCount } = useSelect( ( select ) => { const { getCurrentPostLastRevisionId, getCurrentPostRevisionsCount } = select( editorStore ); return { lastRevisionId: getCurrentPostLastRevisionId(), revisionsCount: getCurrentPostRevisionsCount(), }; }, [] ); if ( ! lastRevisionId || revisionsCount < 2 ) { return null; } return ( <PostTypeSupportCheck supportKeys="revisions"> { children } </PostTypeSupportCheck> ); } export default PostLastRevisionCheck;