MCPcopy
hub / github.com/testing-library/react-hooks-testing-library / useSequence

Function useSequence

src/__tests__/asyncHook.test.ts:4–23  ·  view source on GitHub ↗
(values: string[], intervalMs = 50)

Source from the content-addressed store, hash-verified

2
3describe('async hook tests', () => {
4 const useSequence = (values: string[], intervalMs = 50) => {
5 const [first, ...otherValues] = values
6 const [value, setValue] = useState(() => first)
7 const index = useRef(0)
8
9 useEffect(() => {
10 const interval = setInterval(() => {
11 setValue(otherValues[index.current++])
12 if (index.current >= otherValues.length) {
13 clearInterval(interval)
14 }
15 }, intervalMs)
16 return () => {
17 clearInterval(interval)
18 }
19 // eslint-disable-next-line react-hooks/exhaustive-deps
20 }, otherValues)
21
22 return value
23 }
24
25 runForRenderers(['default', 'dom', 'native', 'server/hydrated'], ({ renderHook }) => {
26 test('should wait for next update', async () => {

Callers 1

asyncHook.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…