Open History to see the last commit
1'use client'
2β
3import * as React from 'react'
4import styles from './ClientWidget.module.css'
5β
6/**
7 * Client widget component with CSS modules.
8 * This is a "use client" component that should have its JS and CSS preloaded
9 * when used inside a server component.
10 */
11export function ClientWidget({ title }: { title: string }) {
12 const [count, setCount] = React.useState(0)
13β
14 return (
15 <div className={styles.widget} data-testid="client-widget">
16 <div className={styles.header}>
17 <span className={styles.badge} data-testid="client-widget-badge">
18 CLIENT COMPONENT
19 </span>
20 </div>
21 <h3 className={styles.title} data-testid="client-widget-title">
22 {title}
23 </h3>
24 <p className={styles.content} data-testid="client-widget-content">
25 This is a client component with CSS modules. The CSS should be preloaded
26 in the document head to prevent flash of unstyled content.
27 </p>
28 <div className={styles.counter}>
29 <button
30 className={styles.button}
31 onClick={() => setCount((c) => c - 1)}
32 data-testid="client-widget-decrement"
33 >
34 -
35 </button>
36 <span className={styles.count} data-testid="client-widget-count">
37 {count}
38 </span>
39 <button
40 className={styles.button}
41 onClick={() => setCount((c) => c + 1)}
42 data-testid="client-widget-increment"
43 >
44 +
45 </button>
46 </div>
47 </div>
48 )
49}