Skip to content

Commit

Permalink
✅ add test for SSR case
Browse files Browse the repository at this point in the history
related:
- #39
- #43
- #40
  • Loading branch information
astoilkov committed Mar 14, 2022
1 parent 47c7715 commit c9b8591
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,30 @@ describe('createLocalStorageStateHook()', () => {
expect(JSON.parse(localStorage.getItem('todos2')!)).toEqual(['first', 'second'])
})

// https://github.com/astoilkov/use-local-storage-state/issues/39
// https://github.com/astoilkov/use-local-storage-state/issues/43
// https://github.com/astoilkov/use-local-storage-state/pull/40
it(`when ssr: true — don't call useEffect() and useLayoutEffect() on first render`, () => {
let calls = 0

function Component() {
useLocalStorageState('color', {
ssr: true,
defaultValue: 'red',
})

useEffect(() => {
calls += 1
})

return null
}

render(<Component />)

expect(calls).toBe(1)
})

// https://github.com/astoilkov/use-local-storage-state/issues/44
it(`setState() shouldn't change between renders`, () => {
function Component() {
Expand Down

0 comments on commit c9b8591

Please sign in to comment.