Download react-use/tests/useLatest.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 716 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/tests/useLatest.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/tests/useLatest.test.ts
-
curl -L -o useLatest.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/tests/useLatest.test.ts
716 Bytes
| import { renderHook } from '@testing-library/react-hooks'; | |
| import useLatest from '../src/useLatest'; | |
| const setUp = () => renderHook(({ state }) => useLatest(state), { initialProps: { state: 0 } }); | |
| it('should return a ref with the latest value on initial render', () => { | |
| const { result } = setUp(); | |
| expect(result.current).toEqual({ current: 0 }); | |
| }); | |
| it('should always return a ref with the latest value after each update', () => { | |
| const { result, rerender } = setUp(); | |
| rerender({ state: 2 }); | |
| expect(result.current).toEqual({ current: 2 }); | |
| rerender({ state: 4 }); | |
| expect(result.current).toEqual({ current: 4 }); | |
| rerender({ state: 6 }); | |
| expect(result.current).toEqual({ current: 6 }); | |
| }); | |