Skip to content

Instantly share code, notes, and snippets.

@JamDev0
Created June 9, 2022 16:34
Show Gist options
  • Select an option

  • Save JamDev0/a7a63f83e0c03f69de5ff22032e9aba3 to your computer and use it in GitHub Desktop.

Select an option

Save JamDev0/a7a63f83e0c03f69de5ff22032e9aba3 to your computer and use it in GitHub Desktop.
import { FormEvent, useState } from 'react';
interface PostFooterProps {
CommentsContent: {
Id: number;
UserName: string;
ProfilePic: string;
IsTheCurrentUser: boolean;
PublishTime: number;
Content: string;
LikesAmount: number;
}[] | null;
}
export function PostFooter({ CommentsContent }: PostFooterProps) {
const [CurrentComments, setCurrentComments] = useState<PostFooterProps["CommentsContent"] | null>(CommentsContent);
function HandleCreateNewComment(event: FormEvent<HTMLFormElement>){
event.preventDefault();
if(event.nativeEvent.submitter.name === "Cancel") {
setIsCreatingComment(!IsCreatingComment);
} else if(event.nativeEvent.submitter.name === "Publish") {
setCurrentComments([...CurrentComments, {
UserName: 'Juan Garcia',
ProfilePic: 'https://avatars.githubusercontent.com/u/61752887?v=4',
IsTheCurrentUser: true,
PublishTime: 0,
Content: TextareaValue,
LikesAmount: 0,
Id: CurrentComments?.length as number + 1,
}]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment