cloudflare/vinext

Public

mirrored fromhttps://github.com/cloudflare/vinextAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
23f9e1e13decb3ee024adc6a091b9252427f8e2e

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/hackernews/components/comment.jsx

39lines · modecode

1'use client';
2
3import { useState } from 'react';
4
5import timeAgo from '../lib/time-ago';
6
7import styles from './comment.module.css';
8
9export default function Comment({ user, text, date, comments, commentsCount }) {
10 const [toggled, setToggled] = useState(false);
11
12 const toggle = () => setToggled(!toggled);
13
14 return (
15 <div className={styles.comment}>
16 <div className={styles.meta} suppressHydrationWarning>
17 {user} {timeAgo(new Date(date))} ago{' '}
18 <span onClick={toggle} className={styles.toggle}>
19 {toggled ? `[+${(commentsCount || 0) + 1}]` : '[-]'}
20 </span>
21 </div>
22
23 {toggled
24 ? null
25 : [
26 <div
27 key="text"
28 className={styles.text}
29 dangerouslySetInnerHTML={{ __html: text }}
30 />,
31 <div key="children" className={styles.children}>
32 {comments.map((comment) => (
33 <Comment key={comment.id} {...comment} />
34 ))}
35 </div>,
36 ]}
37 </div>
38 );
39}
40