@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
27 lines (23 loc) • 692 B
JavaScript
import { __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import { SelectControl } from '@wordpress/components';
import { store as editorStore } from '../../store';
import { useAuthorsQuery } from './hook';
export default function PostAuthorSelect() {
const { editPost } = useDispatch( editorStore );
const { authorId, authorOptions } = useAuthorsQuery();
const setAuthorId = ( value ) => {
const author = Number( value );
editPost( { author } );
};
return (
<SelectControl
className="post-author-selector"
label={ __( 'Author' ) }
options={ authorOptions }
onChange={ setAuthorId }
value={ authorId }
hideLabelFromVision
/>
);
}