Skip to content

Commit

Permalink
improve type
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Oct 30, 2024
1 parent d871796 commit 51e08fe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/fields/src/fields/slug/slug-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { BasePost } from '../../types';
import { getSlug } from './utils';

const SlugView = ( { item }: { item: BasePost } ) => {
const slug = item ? getSlug( item ) : '';
const slug = typeof item === 'object' ? getSlug( item ) : '';
const originalSlugRef = useRef( slug );

useEffect( () => {
Expand All @@ -21,7 +21,7 @@ const SlugView = ( { item }: { item: BasePost } ) => {

const slugToDisplay = slug || originalSlugRef.current;

return `${ slugToDisplay ?? '' }`;
return `${ slugToDisplay }`;
};

export default SlugView;
2 changes: 1 addition & 1 deletion packages/fields/src/fields/slug/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { cleanForSlug } from '@wordpress/url';
import type { BasePost } from '../../types';
import { getItemTitle } from '../../actions/utils';

export const getSlug = ( item: BasePost ) => {
export const getSlug = ( item: BasePost ): string => {
return (
item.slug || cleanForSlug( getItemTitle( item ) ) || item.id.toString()
);
Expand Down

0 comments on commit 51e08fe

Please sign in to comment.