-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[use-local-storage] Add definition (#4455)
- Loading branch information
1 parent
c57729d
commit 56c47e4
Showing
4 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
definitions/npm/use-local-storage_v3.x.x/flow_v0.201.x-/test_use-local-storage_v3.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// @flow | ||
import { describe, it, test } from 'flow-typed-test'; | ||
import useLocalStorage from 'use-local-storage'; | ||
|
||
describe('use-local-storage', () => { | ||
it('works', () => { | ||
const [username, setUsername] = useLocalStorage('name', ''); | ||
setUsername(); | ||
setUsername('test'); | ||
username.toLowerCase(); | ||
|
||
const [a, setA] = useLocalStorage<number>('name', 1); | ||
setA(1); | ||
}); | ||
|
||
it('errors', () => { | ||
// $FlowExpectedError[incompatible-call] | ||
useLocalStorage<number>('name', 'test'); | ||
|
||
const [number, setNumber] = useLocalStorage('name', 1); | ||
// $FlowExpectedError[incompatible-call] | ||
setNumber('test') | ||
}); | ||
|
||
test('options', () => { | ||
useLocalStorage('name', '', {}); | ||
useLocalStorage('name', '', { | ||
serializer: (obj) => { | ||
/* Serialize logic */ | ||
return ''; | ||
}, | ||
parser: (str) => { | ||
/* Parse logic */ | ||
return ''; | ||
}, | ||
logger: console.log, | ||
syncData: false, | ||
}); | ||
|
||
// $FlowExpectedError[incompatible-call] | ||
useLocalStorage('name', '', ''); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
definitions/npm/use-local-storage_v3.x.x/flow_v0.201.x-/use-local-storage_v3.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
declare module 'use-local-storage' { | ||
import type { ReactSetStateFunction } from 'react'; | ||
|
||
declare type Serializer<T> = (object: T | void) => string; | ||
declare type Parser<T> = (val: string) => (T | void); | ||
|
||
declare type Options<T> = Partial<{| | ||
serializer: Serializer<T>, | ||
parser: Parser<T>, | ||
logger: (error: any) => void, | ||
syncData: boolean, | ||
|}>; | ||
|
||
declare module.exports: <T>( | ||
key: string, | ||
defaultValue: T, | ||
options?: Options<T>, | ||
) => [T, ReactSetStateFunction<T | void>]; | ||
} |
43 changes: 43 additions & 0 deletions
43
...tions/npm/use-local-storage_v3.x.x/flow_v0.83.x-v0.200.x/test_use-local-storage_v3.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// @flow | ||
import { describe, it, test } from 'flow-typed-test'; | ||
import useLocalStorage from 'use-local-storage'; | ||
|
||
describe('use-local-storage', () => { | ||
it('works', () => { | ||
const [username, setUsername] = useLocalStorage('name', ''); | ||
setUsername(); | ||
setUsername('test'); | ||
username.toLowerCase(); | ||
|
||
const [a, setA] = useLocalStorage<number>('name', 1); | ||
setA(1); | ||
}); | ||
|
||
it('errors', () => { | ||
// $FlowExpectedError[incompatible-call] | ||
useLocalStorage<number>('name', 'test'); | ||
|
||
const [number, setNumber] = useLocalStorage<number>('name', 1); | ||
// $FlowExpectedError[incompatible-call] | ||
setNumber('test') | ||
}); | ||
|
||
test('options', () => { | ||
useLocalStorage('name', '', {}); | ||
useLocalStorage('name', '', { | ||
serializer: (obj) => { | ||
/* Serialize logic */ | ||
return ''; | ||
}, | ||
parser: (str) => { | ||
/* Parse logic */ | ||
return ''; | ||
}, | ||
logger: console.log, | ||
syncData: false, | ||
}); | ||
|
||
// $FlowExpectedError[incompatible-shape] | ||
useLocalStorage('name', '', ''); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
definitions/npm/use-local-storage_v3.x.x/flow_v0.83.x-v0.200.x/use-local-storage_v3.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
declare module 'use-local-storage' { | ||
import type { ReactSetStateFunction } from 'react'; | ||
|
||
declare type Serializer<T> = (object: T | void) => string; | ||
declare type Parser<T> = (val: string) => (T | void); | ||
declare type Dispatch<A> = (A) => void; | ||
|
||
declare type Options<T> = $Shape<{| | ||
serializer: Serializer<T>, | ||
parser: Parser<T>, | ||
logger: (error: any) => void, | ||
syncData: boolean, | ||
|}>; | ||
|
||
declare module.exports: <T>( | ||
key: string, | ||
defaultValue: T, | ||
options?: Options<T>, | ||
) => [T, ReactSetStateFunction<T | void>]; | ||
} |