From dbca01753330c6c8a1dec629d5675286a45fcf2c Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 4 Mar 2024 11:23:56 +0530 Subject: [PATCH] use alt approach --- components/post-title/index.tsx | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/components/post-title/index.tsx b/components/post-title/index.tsx index 37b324c9..5c43d64b 100644 --- a/components/post-title/index.tsx +++ b/components/post-title/index.tsx @@ -3,18 +3,16 @@ import { RichText, store as blockEditorStore } from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; import { usePost } from '../../hooks'; -/** - * Defines an object type with property `tagName` with type E. - * `tagName` is the HTML tag name (e.g., "h1", "a") that can be used in JSX. - */ -type PolymorphicTagNameProp = { - tagName?: E; -}; +interface PostTitleProps { + tagName?: T; +} -type PolymorphicProps = React.PropsWithChildren & PolymorphicTagNameProp>; +type PostTitlePropsWithOmit = PostTitleProps & Omit, keyof PostTitleProps>; -const defaultElement = 'h1'; -export function PostTitle( { tagName, ...rest }: PolymorphicProps ) { +export const PostTitle = ({ + tagName, + ...rest +}: PostTitlePropsWithOmit ) => { const { postId, postType, isEditable } = usePost(); const [rawTitle = '', setTitle, fullTitle] = useEntityProp( @@ -29,7 +27,7 @@ export function PostTitle( [], ); - const TagName = tagName ?? defaultElement; + const TagName = tagName ?? 'h1'; if (!isEditable) { // eslint-disable-next-line react/no-danger @@ -51,14 +49,3 @@ export function PostTitle( PostTitle.defaultProps = { tagName: 'h1', }; - -function LOL() { - return ( - <> - - - - - - ); -}