rsnext/test/e2e/app-dir/rsc-basic/components/partial-hydration-counter.js
Jiachi Liu 2b99db07f7
Client component directive: use client (#41333)
Replace `'client'` with `'use client'` as client directive for client
components in RSC

x-ref: [slack
thread](https://vercel.slack.com/archives/C035J346QQL/p1665435520907559)

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-10-11 10:26:45 -07:00

22 lines
726 B
JavaScript

'use client'
import { useState, useEffect } from 'react'
export default function Counter() {
const [count, setCount] = useState(0)
useEffect(() => {
// When this component is hydrated, there might be other parts still pending
// on streaming. So we test the interactivity of the document before it's
// fully loaded.
const counter = document.querySelector('button')
const suspense = document.querySelector('.suspense')
counter.click()
setTimeout(() => {
window.partial_hydration_suspense_result = suspense.textContent
window.partial_hydration_counter_result = counter.textContent
}, 0)
}, [])
return <button onClick={() => setCount(count + 1)}>count: {count}</button>
}