From 9543e23ca3c9293959f3ab94c1b78ddea1f279e2 Mon Sep 17 00:00:00 2001 From: xobotyi Date: Wed, 4 Sep 2019 04:10:11 +0300 Subject: [PATCH 01/62] useValidatableState implementation; --- README.md | 1 + docs/useValidatableState.md | 48 ++++++++ src/__stories__/useValidityState.story.tsx | 30 +++++ src/__tests__/useValidatableState.test.ts | 126 +++++++++++++++++++++ src/index.ts | 1 + src/useValidatableState.ts | 46 ++++++++ 6 files changed, 252 insertions(+) create mode 100644 docs/useValidatableState.md create mode 100644 src/__stories__/useValidityState.story.tsx create mode 100644 src/__tests__/useValidatableState.test.ts create mode 100644 src/useValidatableState.ts diff --git a/README.md b/README.md index f54afa21..c08670cc 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ - [`useCounter` and `useNumber`](./docs/useCounter.md) — tracks state of a number. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usecounter--demo) - [`useList`](./docs/useList.md) — tracks state of an array. - [`useMap`](./docs/useMap.md) — tracks state of an object. + - [`useValidatableState`](./docs/useValidatableState.md) — tracks state of an object. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usevalidatablestate--demo)
diff --git a/docs/useValidatableState.md b/docs/useValidatableState.md new file mode 100644 index 00000000..1c84449e --- /dev/null +++ b/docs/useValidatableState.md @@ -0,0 +1,48 @@ +# `useValidatableState` + +Very similar to React's `useState` hook, but extended with validation functionality. +Each time state changes validator invoked and it's result stored to separate state. + +## Usage +```ts +import * as React from 'react'; +import { useCallback } from 'react'; +import { useValidatableState } from 'react-use'; + +const Demo = () => { + const validator = useCallback(s => [s === '' ? null : (s * 1) % 2 === 0], []); + const [state, setState, [isValid]] = useValidatableState(validator, ''); + + return ( +
+
Below field is valid only if number is even
+ { + setState(ev.target.value); + }} + /> + {isValid !== null && {isValid ? 'Valid!' : 'Invalid'}} +
+ ); +}; +``` + +## Reference +```ts +const [state, setState, validity, revalidate] = useValidatableState( + validator: (state, prev, setValidity?)=>[boolean|null, ...any[]], + initialState: any +); +``` +- `state` and `setState` are the same with React's `useState` hook; +- **`validity`**_`: [boolean|null, ...any[]]`_ result of validity check. First element is strictly nullable boolean, but others can contain arbitrary data; +- **`revalidate`**_`: ()=>void`_ runs validator once again +- **`validator`** should return an array suitable for validity state described above; + - `state` - current state; + - `prev` - previous state; + - `setValidity` - if defined hook will not trigger validity change automatically. Useful for async validators; +- `initialState` same with `useState` hook; diff --git a/src/__stories__/useValidityState.story.tsx b/src/__stories__/useValidityState.story.tsx new file mode 100644 index 00000000..66e9651e --- /dev/null +++ b/src/__stories__/useValidityState.story.tsx @@ -0,0 +1,30 @@ +import { storiesOf } from '@storybook/react'; +import * as React from 'react'; +import { useCallback } from 'react'; +import { useValidatableState } from '../index'; +import ShowDocs from './util/ShowDocs'; + +const Demo = () => { + const validator = useCallback(s => [s === '' ? null : (s * 1) % 2 === 0], []); + const [state, setState, [isValid]] = useValidatableState(validator, ''); + + return ( +
+
Below field is valid only if number is even
+ { + setState(ev.target.value); + }} + /> + {isValid !== null && {isValid ? 'Valid!' : 'Invalid'}} +
+ ); +}; + +storiesOf('State|useValidatableState', module) + .add('Docs', () => ) + .add('Demo', () => ); diff --git a/src/__tests__/useValidatableState.test.ts b/src/__tests__/useValidatableState.test.ts new file mode 100644 index 00000000..0e0bc515 --- /dev/null +++ b/src/__tests__/useValidatableState.test.ts @@ -0,0 +1,126 @@ +import { act, renderHook, RenderHookResult } from '@testing-library/react-hooks'; +import { useValidatableState } from '../index'; +import { UseValidatableStateReturn, Validator } from '../useValidatableState'; + +interface Mock extends jest.Mock {} + +describe('useValidatableState', () => { + it('should be defined', () => { + expect(useValidatableState).toBeDefined(); + }); + + function getHook( + fn: Validator = jest.fn(() => {}), + initialState: any = null + ): [Mock | Function, RenderHookResult<{ validator: Validator; init: any }, UseValidatableStateReturn>] { + return [ + fn, + renderHook(({ validator, init }) => useValidatableState(validator as Function, init), { + initialProps: { + validator: fn, + init: initialState, + }, + }), + ]; + } + + it('should return an array of four elements', () => { + const [, hook] = getHook(); + + expect(Array.isArray(hook.result.current)).toBe(true); + expect(hook.result.current.length).toBe(4); + }); + + it('first two elements should act like regular setState', () => { + const [, hook] = getHook(jest.fn(), 3); + const [, setState] = hook.result.current; + + expect(hook.result.current[0]).toBe(3); + act(() => setState(4)); + expect(hook.result.current[0]).toBe(4); + act(() => setState(prevState => prevState + 1)); + expect(hook.result.current[0]).toBe(5); + }); + + it('validator have to be called on init plus on each state update', () => { + const [spy, hook] = getHook(jest.fn(), 3); + const [, setState] = hook.result.current; + + expect(spy).toHaveBeenCalledTimes(1); + act(() => setState(4)); + expect(spy).toHaveBeenCalledTimes(2); + act(() => setState(prevState => prevState + 1)); + expect(spy).toHaveBeenCalledTimes(3); + }); + + it('third element of returned array should represent validity state', () => { + const [, hook] = getHook(jest.fn(state => [state % 2 === 0]), 3); + let [, setState, [isValid]] = hook.result.current; + + expect(isValid).toBe(false); + act(() => setState(prevState => prevState + 1)); + + [, setState, [isValid]] = hook.result.current; + expect(isValid).toBe(true); + act(() => setState(5)); + + [, setState, [isValid]] = hook.result.current; + expect(isValid).toBe(false); + }); + + it('should recalculate validity on validator change', () => { + const [, hook] = getHook(jest.fn(state => [state % 2 === 0]), 3); + let [, setState, [isValid]] = hook.result.current; + + expect(isValid).toBe(false); + + hook.rerender({ validator: jest.fn(state => [state % 2 === 1]), init: 3 }); + + [, setState, [isValid]] = hook.result.current; + expect(isValid).toBe(true); + act(() => setState(prevState => prevState + 1)); + + [, setState, [isValid]] = hook.result.current; + expect(isValid).toBe(false); + }); + + it('forth element of returned array should re-call validation', () => { + const [spy, hook] = getHook(jest.fn(), 3); + const [, , , validate] = hook.result.current; + + expect(spy).toHaveBeenCalledTimes(1); + act(() => validate()); + expect(spy).toHaveBeenCalledTimes(2); + }); + + it('should pass to validator two parameters: first - current state, second - previous state', () => { + const [spy, hook] = getHook(jest.fn(), 3); + const [, setState] = hook.result.current; + + act(() => setState(4)); + act(() => setState(prevState => prevState + 1)); + expect((spy as Mock).mock.calls[0][0]).toBe(3); + expect((spy as Mock).mock.calls[0][1]).toBe(null); + expect((spy as Mock).mock.calls[1][0]).toBe(4); + expect((spy as Mock).mock.calls[1][1]).toBe(3); + expect((spy as Mock).mock.calls[2][0]).toBe(5); + expect((spy as Mock).mock.calls[2][1]).toBe(4); + }); + + it('if validator expects 3 parameters it should pass a validity setter there', () => { + const [spy, hook] = getHook(jest.fn((state, _prevState, setValidity) => setValidity!([state % 2 === 0])), 3); + let [, setState, [isValid]] = hook.result.current; + + expect(typeof (spy as Mock).mock.calls[0][2]).toBe('function'); + + expect(isValid).toBe(false); + act(() => setState(prevState => prevState + 1)); + + [, setState, [isValid]] = hook.result.current; + expect(isValid).toBe(true); + act(() => setState(5)); + + [, setState, [isValid]] = hook.result.current; + expect(isValid).toBe(false); + }); +}); diff --git a/src/index.ts b/src/index.ts index b3514a71..412e1bd7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -86,6 +86,7 @@ export { default as useUpdate } from './useUpdate'; export { default as useUpdateEffect } from './useUpdateEffect'; export { default as useUpsert } from './useUpsert'; export { default as useVideo } from './useVideo'; +export { default as useValidatableState } from './useValidatableState'; export { useWait, Waiter } from './useWait'; export { default as useWindowScroll } from './useWindowScroll'; export { default as useWindowSize } from './useWindowSize'; diff --git a/src/useValidatableState.ts b/src/useValidatableState.ts new file mode 100644 index 00000000..2d0b9b46 --- /dev/null +++ b/src/useValidatableState.ts @@ -0,0 +1,46 @@ +import { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react'; + +export type ValidityState = [boolean | null, ...any[]]; +export type DispatchValidityState = Dispatch>; + +export type Validator = + | { + (state?: State, prev?: State): StateValidity; + (state?: State, prev?: State, setValidity?: DispatchValidityState): void; + } + | Function; + +export type ValidateFn = () => void; + +export type UseValidatableStateReturn = [ + State, + Dispatch>, + StateValidity, + ValidateFn +]; + +export default function useValidatableState( + validator: Validator, + initialState?: State +): UseValidatableStateReturn { + const prevState = useRef(null); + const [state, setState] = useState(initialState!); + const [validity, setValidity] = useState([null] as StateValidity); + + const validate = useCallback(() => { + if (validator.length === 3) { + validator(state, prevState.current, setValidity as DispatchValidityState); + } else { + setValidity(validator(state, prevState.current)); + } + }, [state, validator]); + + useEffect(() => { + validate(); + }, [validate, state]); + useEffect(() => { + prevState.current = state; + }, [state]); + + return [state, setState, validity, validate]; +} From 6dbed8b54cc5c1e5517253f934d2eb8588568dc4 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 16 Sep 2019 00:35:21 +0000 Subject: [PATCH 02/62] Update dependency ts-node to v8.4.1 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index efc6f667..8cdba5d0 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "rxjs": "6.5.3", "semantic-release": "15.13.24", "ts-loader": "6.1.0", - "ts-node": "8.3.0", + "ts-node": "8.4.1", "tslint": "5.20.0", "tslint-config-prettier": "1.18.0", "tslint-eslint-rules": "5.4.0", diff --git a/yarn.lock b/yarn.lock index c8bab952..ed408775 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12321,10 +12321,10 @@ ts-loader@6.1.0: micromatch "^4.0.0" semver "^6.0.0" -ts-node@8.3.0: - version "8.3.0" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.3.0.tgz#e4059618411371924a1fb5f3b125915f324efb57" - integrity sha512-dyNS/RqyVTDcmNM4NIBAeDMpsAdaQ+ojdf0GOLqE6nwJOgzEkdRNzJywhDfwnuvB10oa6NLVG1rUJQCpRN7qoQ== +ts-node@8.4.1: + version "8.4.1" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.4.1.tgz#270b0dba16e8723c9fa4f9b4775d3810fd994b4f" + integrity sha512-5LpRN+mTiCs7lI5EtbXmF/HfMeCjzt7DH9CZwtkr6SywStrNQC723wG+aOWFiLNn7zT3kD/RnFqi3ZUfr4l5Qw== dependencies: arg "^4.1.0" diff "^4.0.1" From e2616735a3dbdba1a4521bf5c0244e762de074f6 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 17 Sep 2019 17:28:20 +0000 Subject: [PATCH 03/62] Update dependency tslint-react to v4.1.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8cdba5d0..bea0b92d 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "tslint-config-prettier": "1.18.0", "tslint-eslint-rules": "5.4.0", "tslint-plugin-prettier": "2.0.1", - "tslint-react": "4.0.0", + "tslint-react": "4.1.0", "typescript": "3.5.3" }, "config": { diff --git a/yarn.lock b/yarn.lock index ed408775..3af427f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12365,10 +12365,10 @@ tslint-plugin-prettier@2.0.1: lines-and-columns "^1.1.6" tslib "^1.7.1" -tslint-react@4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/tslint-react/-/tslint-react-4.0.0.tgz#b4bb4c01c32448cb14d23f143a2f5e4989bb961e" - integrity sha512-9fNE0fm9zNDx1+b6hgy8rgDN2WsQLRiIrn3+fbqm0tazBVF6jiaCFAITxmU+WSFWYE03Xhp1joCircXOe1WVAQ== +tslint-react@4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/tslint-react/-/tslint-react-4.1.0.tgz#7153b724a8cfbea52423d0ffa469e8eba3bcc834" + integrity sha512-Y7CbFn09X7Mpg6rc7t/WPbmjx9xPI8p1RsQyiGCLWgDR6sh3+IBSlT+bEkc0PSZcWwClOkqq2wPsID8Vep6szQ== dependencies: tsutils "^3.9.1" From 86c1f87e8ec22f4023b147568a679089b84b5148 Mon Sep 17 00:00:00 2001 From: Ward Oosterlijnck Date: Wed, 18 Sep 2019 15:52:54 +0200 Subject: [PATCH 04/62] docs: added useSize initial size parameter, related #584 --- docs/useSize.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/useSize.md b/docs/useSize.md index ec0d90b8..3e8868f5 100644 --- a/docs/useSize.md +++ b/docs/useSize.md @@ -9,7 +9,8 @@ import {useSize} from 'react-use'; const Demo = () => { const [sized, {width, height}] = useSize( - ({width}) =>
Size me up! ({width}px)
+ ({width}) =>
Size me up! ({width}px)
, + { width: 100, height: 100 } ); return ( @@ -21,3 +22,12 @@ const Demo = () => { ); }; ``` + +## Reference + +```js +useSize(element, initialSize); +``` + +- `element` — sized element. +- `initialSize` — initial size containing a `width` and `height` key. From b425eb52f904c0d71fa998662fb1e80f2ed85dd5 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 20 Sep 2019 07:25:19 +0000 Subject: [PATCH 05/62] chore(deps): update dependency ts-loader to v6.1.1 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index bea0b92d..15c9d88a 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "rimraf": "3.0.0", "rxjs": "6.5.3", "semantic-release": "15.13.24", - "ts-loader": "6.1.0", + "ts-loader": "6.1.1", "ts-node": "8.4.1", "tslint": "5.20.0", "tslint-config-prettier": "1.18.0", diff --git a/yarn.lock b/yarn.lock index 3af427f4..110ffd47 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12310,10 +12310,10 @@ ts-easing@^0.2.0: resolved "https://registry.yarnpkg.com/ts-easing/-/ts-easing-0.2.0.tgz#c8a8a35025105566588d87dbda05dd7fbfa5a4ec" integrity sha512-Z86EW+fFFh/IFB1fqQ3/+7Zpf9t2ebOAxNI/V6Wo7r5gqiqtxmgTlQ1qbqQcjLKYeSHPTsEmvlJUDg/EuL0uHQ== -ts-loader@6.1.0: - version "6.1.0" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-6.1.0.tgz#999cb0a7644f9c7c6c0901802dce50ceb0a76e5b" - integrity sha512-7JedeOu2rsYHQDEr2fwmMozABwbQTZXEaEMZPSIWG7gpzRefOLJCqwdazcegHtyaxp04PeEgs/b0m08WMpnIzQ== +ts-loader@6.1.1: + version "6.1.1" + resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-6.1.1.tgz#f30c68aa1ce59fa266f0bb70a36959ca68f40ddc" + integrity sha512-AoOek8ZWJlWwTRH5ttNmZPBRcASUJZc8wc8E/2PGOXef96H97J8KaLXaW/zUnvyFjvCoRBhTGh9ZIMKL1arcCA== dependencies: chalk "^2.3.0" enhanced-resolve "^4.0.0" From 18e7c547609b6f3cf11b1080c95ed7cfbe83e302 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sat, 21 Sep 2019 06:45:04 +0000 Subject: [PATCH 06/62] chore(deps): update dependency ts-loader to v6.1.2 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 15c9d88a..47251ab7 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "rimraf": "3.0.0", "rxjs": "6.5.3", "semantic-release": "15.13.24", - "ts-loader": "6.1.1", + "ts-loader": "6.1.2", "ts-node": "8.4.1", "tslint": "5.20.0", "tslint-config-prettier": "1.18.0", diff --git a/yarn.lock b/yarn.lock index 110ffd47..3c84da6c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12310,10 +12310,10 @@ ts-easing@^0.2.0: resolved "https://registry.yarnpkg.com/ts-easing/-/ts-easing-0.2.0.tgz#c8a8a35025105566588d87dbda05dd7fbfa5a4ec" integrity sha512-Z86EW+fFFh/IFB1fqQ3/+7Zpf9t2ebOAxNI/V6Wo7r5gqiqtxmgTlQ1qbqQcjLKYeSHPTsEmvlJUDg/EuL0uHQ== -ts-loader@6.1.1: - version "6.1.1" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-6.1.1.tgz#f30c68aa1ce59fa266f0bb70a36959ca68f40ddc" - integrity sha512-AoOek8ZWJlWwTRH5ttNmZPBRcASUJZc8wc8E/2PGOXef96H97J8KaLXaW/zUnvyFjvCoRBhTGh9ZIMKL1arcCA== +ts-loader@6.1.2: + version "6.1.2" + resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-6.1.2.tgz#ff6bc767334970226438949fbde2e211147a1325" + integrity sha512-dudxFKm0Ellrg/gLNlu+97/UgwvoMK0SdUVImPUSzq3IcRUVtShylZvcMX+CgvCQL1BEKb913NL0gAP1GA/OFw== dependencies: chalk "^2.3.0" enhanced-resolve "^4.0.0" From 24b614c3244283b311b0b56d6374c8689bfa824c Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sun, 22 Sep 2019 10:42:52 +0000 Subject: [PATCH 07/62] chore(deps): update dependency lint-staged to v9.3.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 47251ab7..b81ccb6e 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "husky": "3.0.5", "jest": "24.9.0", "keyboardjs": "2.5.1", - "lint-staged": "9.2.5", + "lint-staged": "9.3.0", "markdown-loader": "5.1.0", "prettier": "1.18.2", "raf-stub": "3.0.0", diff --git a/yarn.lock b/yarn.lock index 3c84da6c..e1f52848 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7925,10 +7925,10 @@ lines-and-columns@^1.1.6: resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= -lint-staged@9.2.5: - version "9.2.5" - resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.2.5.tgz#5a3e1e0a539a403bd7f88542bc3d34ce52efdbb3" - integrity sha512-d99gTBFMJ29159+9iRvaMEQstmNcPAbQbhHSYw6D/1FncvFdIj8lWHztaq3Uq+tbZPABHXQ/fyN7Rp1QwF8HIw== +lint-staged@9.3.0: + version "9.3.0" + resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.3.0.tgz#522a79f166050ab5777887348f2cbdb03f71acac" + integrity sha512-OuL3xo6XpBErl16+3W9PdnFmgeGp12lM8I1Ii/B56S8Edy1kyrf4W8VD4IBn9v17QlutRQEWUJ54YF/VVQ7J2A== dependencies: chalk "^2.4.2" commander "^2.20.0" From adce59ec327557837603e51c68694c01ff754f1a Mon Sep 17 00:00:00 2001 From: Yingya Zhang Date: Tue, 24 Sep 2019 01:07:51 +0800 Subject: [PATCH 08/62] fix: remove attempt from deps of retry in useAsyncRetry (#614) --- src/useAsyncRetry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/useAsyncRetry.ts b/src/useAsyncRetry.ts index 1c11578f..519c2b5d 100644 --- a/src/useAsyncRetry.ts +++ b/src/useAsyncRetry.ts @@ -20,7 +20,7 @@ const useAsyncRetry = (fn: () => Promise, deps: DependencyList = []) => { } setAttempt(currentAttempt => currentAttempt + 1); - }, [...deps, stateLoading, attempt]); + }, [...deps, stateLoading]); return { ...state, retry }; }; From 64048a0039f6c4c4537151f624e5a03d051f79c0 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 23 Sep 2019 17:09:56 +0000 Subject: [PATCH 09/62] chore(release): 12.2.1 [skip ci] ## [12.2.1](https://github.com/streamich/react-use/compare/v12.2.0...v12.2.1) (2019-09-23) ### Bug Fixes * remove attempt from deps of retry in useAsyncRetry ([#614](https://github.com/streamich/react-use/issues/614)) ([adce59e](https://github.com/streamich/react-use/commit/adce59e)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3396f4c6..0d0dd3eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [12.2.1](https://github.com/streamich/react-use/compare/v12.2.0...v12.2.1) (2019-09-23) + + +### Bug Fixes + +* remove attempt from deps of retry in useAsyncRetry ([#614](https://github.com/streamich/react-use/issues/614)) ([adce59e](https://github.com/streamich/react-use/commit/adce59e)) + # [12.2.0](https://github.com/streamich/react-use/compare/v12.1.0...v12.2.0) (2019-09-02) diff --git a/package.json b/package.json index b81ccb6e..d9a72dce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-use", - "version": "12.2.0", + "version": "12.2.1", "description": "Collection of React Hooks", "main": "lib/index.js", "module": "esm/index.js", From e6077c1e27f5c8a0536fc4caa4072dc9aab145b2 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 23 Sep 2019 21:30:22 +0000 Subject: [PATCH 10/62] chore(deps): update babel monorepo to v7.6.2 --- package.json | 4 +- yarn.lock | 158 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 111 insertions(+), 51 deletions(-) diff --git a/package.json b/package.json index d9a72dce..97850eb9 100644 --- a/package.json +++ b/package.json @@ -61,9 +61,9 @@ "react-dom": "^16.8.0" }, "devDependencies": { - "@babel/core": "7.6.0", + "@babel/core": "7.6.2", "@babel/plugin-syntax-dynamic-import": "7.2.0", - "@babel/preset-env": "7.6.0", + "@babel/preset-env": "7.6.2", "@babel/preset-react": "7.0.0", "@babel/preset-typescript": "7.6.0", "@semantic-release/changelog": "3.0.4", diff --git a/yarn.lock b/yarn.lock index e1f52848..cccb45ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -36,17 +36,17 @@ semver "^5.4.1" source-map "^0.5.0" -"@babel/core@7.6.0": - version "7.6.0" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.6.0.tgz#9b00f73554edd67bebc86df8303ef678be3d7b48" - integrity sha512-FuRhDRtsd6IptKpHXAa+4WPZYY2ZzgowkbLBecEDDSje1X/apG7jQM33or3NdOmjXBKWGOg4JmSiRfUfuTtHXw== +"@babel/core@7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.6.2.tgz#069a776e8d5e9eefff76236bc8845566bd31dd91" + integrity sha512-l8zto/fuoZIbncm+01p8zPSDZu/VuuJhAfA7d/AbzM09WR7iVhavvfNDYCNpo1VvLk6E6xgAoP9P+/EMJHuRkQ== dependencies: "@babel/code-frame" "^7.5.5" - "@babel/generator" "^7.6.0" - "@babel/helpers" "^7.6.0" - "@babel/parser" "^7.6.0" + "@babel/generator" "^7.6.2" + "@babel/helpers" "^7.6.2" + "@babel/parser" "^7.6.2" "@babel/template" "^7.6.0" - "@babel/traverse" "^7.6.0" + "@babel/traverse" "^7.6.2" "@babel/types" "^7.6.0" convert-source-map "^1.1.0" debug "^4.1.0" @@ -87,16 +87,15 @@ source-map "^0.5.0" trim-right "^1.0.1" -"@babel/generator@^7.6.0": - version "7.6.0" - resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.6.0.tgz#e2c21efbfd3293ad819a2359b448f002bfdfda56" - integrity sha512-Ms8Mo7YBdMMn1BYuNtKuP/z0TgEIhbcyB8HVR6PPNYp4P61lMsABiS4A3VG1qznjXVCf3r+fVHhm4efTYVsySA== +"@babel/generator@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.6.2.tgz#dac8a3c2df118334c2a29ff3446da1636a8f8c03" + integrity sha512-j8iHaIW4gGPnViaIHI7e9t/Hl8qLjERI6DcV9kEpAIDJsAOrcnXqRS7t+QbhL76pwbtqP+QCQLL0z1CyVmtjjQ== dependencies: "@babel/types" "^7.6.0" jsesc "^2.5.1" lodash "^4.17.13" source-map "^0.5.0" - trim-right "^1.0.1" "@babel/helper-annotate-as-pure@^7.0.0": version "7.0.0" @@ -294,13 +293,13 @@ "@babel/traverse" "^7.5.5" "@babel/types" "^7.5.5" -"@babel/helpers@^7.6.0": - version "7.6.0" - resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.6.0.tgz#21961d16c6a3c3ab597325c34c465c0887d31c6e" - integrity sha512-W9kao7OBleOjfXtFGgArGRX6eCP0UEcA2ZWEWNkJdRZnHhW4eEbeswbG3EwaRsnQUAEGWYgMq1HsIXuNNNy2eQ== +"@babel/helpers@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.6.2.tgz#681ffe489ea4dcc55f23ce469e58e59c1c045153" + integrity sha512-3/bAUL8zZxYs1cdX2ilEE0WobqbCmKWr/889lf2SS0PpDcpEIY8pb1CCyz0pEcX3pEb+MCbks1jIokz2xLtGTA== dependencies: "@babel/template" "^7.6.0" - "@babel/traverse" "^7.6.0" + "@babel/traverse" "^7.6.2" "@babel/types" "^7.6.0" "@babel/highlight@^7.0.0": @@ -322,6 +321,11 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.6.0.tgz#3e05d0647432a8326cb28d0de03895ae5a57f39b" integrity sha512-+o2q111WEx4srBs7L9eJmcwi655eD8sXniLqMB93TBK9GrNzGrxDWSjiqz2hLU0Ha8MTXFIP0yd9fNdP+m43ZQ== +"@babel/parser@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.6.2.tgz#205e9c95e16ba3b8b96090677a67c9d6075b70a1" + integrity sha512-mdFqWrSPCmikBoaBYMuBulzTIKuXVPtEISFbRRVNwMWpCms/hmE2kRq0bblUHaNRKrjRlmVbx1sDHmjmRgD2Xg== + "@babel/plugin-proposal-async-generator-functions@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.2.0.tgz#b289b306669dce4ad20b0252889a15768c9d417e" @@ -380,6 +384,14 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-object-rest-spread" "^7.2.0" +"@babel/plugin-proposal-object-rest-spread@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.6.2.tgz#8ffccc8f3a6545e9f78988b6bf4fe881b88e8096" + integrity sha512-LDBXlmADCsMZV1Y9OQwMc0MyGZ8Ta/zlD9N67BfQT8uYwkRswiu2hU6nJKrjrt/58aH/vqfQlR/9yId/7A2gWw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-object-rest-spread" "^7.2.0" + "@babel/plugin-proposal-optional-catch-binding@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.2.0.tgz#135d81edb68a081e55e56ec48541ece8065c38f5" @@ -397,6 +409,15 @@ "@babel/helper-regex" "^7.4.4" regexpu-core "^4.5.4" +"@babel/plugin-proposal-unicode-property-regex@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.6.2.tgz#05413762894f41bfe42b9a5e80919bd575dcc802" + integrity sha512-NxHETdmpeSCtiatMRYWVJo7266rrvAC3DTeG5exQBIH/fMIUK7ejDNznBbn3HQl/o9peymRRg7Yqkx6PdUXmMw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.4.4" + regexpu-core "^4.6.0" + "@babel/plugin-syntax-async-generators@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.2.0.tgz#69e1f0db34c6f5a0cf7e2b3323bf159a76c8cb7f" @@ -491,10 +512,10 @@ "@babel/helper-plugin-utils" "^7.0.0" lodash "^4.17.13" -"@babel/plugin-transform-block-scoping@^7.6.0": - version "7.6.0" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.6.0.tgz#c49e21228c4bbd4068a35667e6d951c75439b1dc" - integrity sha512-tIt4E23+kw6TgL/edACZwP1OUKrjOTyMrFMLoT5IOFrfMRabCgekjqFd5o6PaAMildBu46oFkekIdMuGkkPEpA== +"@babel/plugin-transform-block-scoping@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.6.2.tgz#96c33ab97a9ae500cc6f5b19e04a7e6553360a79" + integrity sha512-zZT8ivau9LOQQaOGC7bQLQOT4XPkPXgN2ERfUgk1X8ql+mVkLc4E8eKk+FO3o0154kxzqenWCorfmEXpEZcrSQ== dependencies: "@babel/helper-plugin-utils" "^7.0.0" lodash "^4.17.13" @@ -564,6 +585,15 @@ "@babel/helper-regex" "^7.4.4" regexpu-core "^4.5.4" +"@babel/plugin-transform-dotall-regex@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-dotall-regex/-/plugin-transform-dotall-regex-7.6.2.tgz#44abb948b88f0199a627024e1508acaf8dc9b2f9" + integrity sha512-KGKT9aqKV+9YMZSkowzYoYEiHqgaDhGmPNZlZxX6UeHC4z30nC1J9IrZuGqbYFB1jaIGdv91ujpze0exiVK8bA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.4.4" + regexpu-core "^4.6.0" + "@babel/plugin-transform-duplicate-keys@^7.2.0", "@babel/plugin-transform-duplicate-keys@^7.5.0": version "7.5.0" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.5.0.tgz#c5dbf5106bf84cdf691222c0974c12b1df931853" @@ -669,12 +699,12 @@ dependencies: regexp-tree "^0.1.6" -"@babel/plugin-transform-named-capturing-groups-regex@^7.6.0": - version "7.6.0" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.6.0.tgz#1e6e663097813bb4f53d42df0750cf28ad3bb3f1" - integrity sha512-jem7uytlmrRl3iCAuQyw8BpB4c4LWvSpvIeXKpMb+7j84lkx4m4mYr5ErAcmN5KM7B6BqrAvRGjBIbbzqCczew== +"@babel/plugin-transform-named-capturing-groups-regex@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.6.2.tgz#c1ca0bb84b94f385ca302c3932e870b0fb0e522b" + integrity sha512-xBdB+XOs+lgbZc2/4F5BVDVcDNS4tcSKQc96KmlqLEAwz6tpYPEvPdmDfvVG0Ssn8lAhronaRs6Z6KSexIpK5g== dependencies: - regexp-tree "^0.1.13" + regexpu-core "^4.6.0" "@babel/plugin-transform-new-target@^7.4.0", "@babel/plugin-transform-new-target@^7.4.4": version "7.4.4" @@ -785,6 +815,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-transform-spread@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-spread/-/plugin-transform-spread-7.6.2.tgz#fc77cf798b24b10c46e1b51b1b88c2bf661bb8dd" + integrity sha512-DpSvPFryKdK1x+EDJYCy28nmAaIMdxmhot62jAXF/o99iA33Zj2Lmcp3vDmz+MUh0LNYVPvfj5iC3feb3/+PFg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-transform-sticky-regex@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-sticky-regex/-/plugin-transform-sticky-regex-7.2.0.tgz#a1e454b5995560a9c1e0d537dfc15061fd2687e1" @@ -834,6 +871,15 @@ "@babel/helper-regex" "^7.4.4" regexpu-core "^4.5.4" +"@babel/plugin-transform-unicode-regex@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.6.2.tgz#b692aad888a7e8d8b1b214be6b9dc03d5031f698" + integrity sha512-orZI6cWlR3nk2YmYdb0gImrgCUwb5cBUwjf6Ks6dvNVvXERkwtJWOQaEOjPiu0Gu1Tq6Yq/hruCZZOOi9F34Dw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.4.4" + regexpu-core "^4.6.0" + "@babel/preset-env@7.4.3": version "7.4.3" resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.4.3.tgz#e71e16e123dc0fbf65a52cbcbcefd072fbd02880" @@ -888,19 +934,19 @@ js-levenshtein "^1.1.3" semver "^5.5.0" -"@babel/preset-env@7.6.0": - version "7.6.0" - resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.6.0.tgz#aae4141c506100bb2bfaa4ac2a5c12b395619e50" - integrity sha512-1efzxFv/TcPsNXlRhMzRnkBFMeIqBBgzwmZwlFDw5Ubj0AGLeufxugirwZmkkX/ayi3owsSqoQ4fw8LkfK9SYg== +"@babel/preset-env@7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.6.2.tgz#abbb3ed785c7fe4220d4c82a53621d71fc0c75d3" + integrity sha512-Ru7+mfzy9M1/YTEtlDS8CD45jd22ngb9tXnn64DvQK3ooyqSw9K4K9DUWmYknTTVk4TqygL9dqCrZgm1HMea/Q== dependencies: "@babel/helper-module-imports" "^7.0.0" "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-proposal-async-generator-functions" "^7.2.0" "@babel/plugin-proposal-dynamic-import" "^7.5.0" "@babel/plugin-proposal-json-strings" "^7.2.0" - "@babel/plugin-proposal-object-rest-spread" "^7.5.5" + "@babel/plugin-proposal-object-rest-spread" "^7.6.2" "@babel/plugin-proposal-optional-catch-binding" "^7.2.0" - "@babel/plugin-proposal-unicode-property-regex" "^7.4.4" + "@babel/plugin-proposal-unicode-property-regex" "^7.6.2" "@babel/plugin-syntax-async-generators" "^7.2.0" "@babel/plugin-syntax-dynamic-import" "^7.2.0" "@babel/plugin-syntax-json-strings" "^7.2.0" @@ -909,11 +955,11 @@ "@babel/plugin-transform-arrow-functions" "^7.2.0" "@babel/plugin-transform-async-to-generator" "^7.5.0" "@babel/plugin-transform-block-scoped-functions" "^7.2.0" - "@babel/plugin-transform-block-scoping" "^7.6.0" + "@babel/plugin-transform-block-scoping" "^7.6.2" "@babel/plugin-transform-classes" "^7.5.5" "@babel/plugin-transform-computed-properties" "^7.2.0" "@babel/plugin-transform-destructuring" "^7.6.0" - "@babel/plugin-transform-dotall-regex" "^7.4.4" + "@babel/plugin-transform-dotall-regex" "^7.6.2" "@babel/plugin-transform-duplicate-keys" "^7.5.0" "@babel/plugin-transform-exponentiation-operator" "^7.2.0" "@babel/plugin-transform-for-of" "^7.4.4" @@ -924,7 +970,7 @@ "@babel/plugin-transform-modules-commonjs" "^7.6.0" "@babel/plugin-transform-modules-systemjs" "^7.5.0" "@babel/plugin-transform-modules-umd" "^7.2.0" - "@babel/plugin-transform-named-capturing-groups-regex" "^7.6.0" + "@babel/plugin-transform-named-capturing-groups-regex" "^7.6.2" "@babel/plugin-transform-new-target" "^7.4.4" "@babel/plugin-transform-object-super" "^7.5.5" "@babel/plugin-transform-parameters" "^7.4.4" @@ -932,11 +978,11 @@ "@babel/plugin-transform-regenerator" "^7.4.5" "@babel/plugin-transform-reserved-words" "^7.2.0" "@babel/plugin-transform-shorthand-properties" "^7.2.0" - "@babel/plugin-transform-spread" "^7.2.0" + "@babel/plugin-transform-spread" "^7.6.2" "@babel/plugin-transform-sticky-regex" "^7.2.0" "@babel/plugin-transform-template-literals" "^7.4.4" "@babel/plugin-transform-typeof-symbol" "^7.2.0" - "@babel/plugin-transform-unicode-regex" "^7.4.4" + "@babel/plugin-transform-unicode-regex" "^7.6.2" "@babel/types" "^7.6.0" browserslist "^4.6.0" core-js-compat "^3.1.1" @@ -1089,16 +1135,16 @@ globals "^11.1.0" lodash "^4.17.13" -"@babel/traverse@^7.6.0": - version "7.6.0" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.6.0.tgz#389391d510f79be7ce2ddd6717be66d3fed4b516" - integrity sha512-93t52SaOBgml/xY74lsmt7xOR4ufYvhb5c5qiM6lu4J/dWGMAfAh6eKw4PjLes6DI6nQgearoxnFJk60YchpvQ== +"@babel/traverse@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.6.2.tgz#b0e2bfd401d339ce0e6c05690206d1e11502ce2c" + integrity sha512-8fRE76xNwNttVEF2TwxJDGBLWthUkHWSldmfuBzVRmEDWOtu4XdINTgN7TDWzuLg4bbeIMLvfMFD9we5YcWkRQ== dependencies: "@babel/code-frame" "^7.5.5" - "@babel/generator" "^7.6.0" + "@babel/generator" "^7.6.2" "@babel/helper-function-name" "^7.1.0" "@babel/helper-split-export-declaration" "^7.4.4" - "@babel/parser" "^7.6.0" + "@babel/parser" "^7.6.2" "@babel/types" "^7.6.0" debug "^4.1.0" globals "^11.1.0" @@ -10738,6 +10784,13 @@ regenerate-unicode-properties@^8.0.2: dependencies: regenerate "^1.4.0" +regenerate-unicode-properties@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.1.0.tgz#ef51e0f0ea4ad424b77bf7cb41f3e015c70a3f0e" + integrity sha512-LGZzkgtLY79GeXLm8Dp0BVLdQlWICzBnJz/ipWUgo59qBaZ+BHtq51P2q1uVZlppMuUAT37SDk39qUbjTWB7bA== + dependencies: + regenerate "^1.4.0" + regenerate@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" @@ -10773,11 +10826,6 @@ regex-not@^1.0.0, regex-not@^1.0.2: extend-shallow "^3.0.2" safe-regex "^1.1.0" -regexp-tree@^0.1.13: - version "0.1.13" - resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.13.tgz#5b19ab9377edc68bc3679256840bb29afc158d7f" - integrity sha512-hwdV/GQY5F8ReLZWO+W1SRoN5YfpOKY6852+tBFcma72DKBIcHjPRIlIvQN35bCOljuAfP2G2iB0FC/w236mUw== - regexp-tree@^0.1.6: version "0.1.10" resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.10.tgz#d837816a039c7af8a8d64d7a7c3cf6a1d93450bc" @@ -10802,6 +10850,18 @@ regexpu-core@^4.5.4: unicode-match-property-ecmascript "^1.0.4" unicode-match-property-value-ecmascript "^1.1.0" +regexpu-core@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-4.6.0.tgz#2037c18b327cfce8a6fea2a4ec441f2432afb8b6" + integrity sha512-YlVaefl8P5BnFYOITTNzDvan1ulLOiXJzCNZxduTIosN17b87h3bvG9yHMoHaRuo88H4mQ06Aodj5VtYGGGiTg== + dependencies: + regenerate "^1.4.0" + regenerate-unicode-properties "^8.1.0" + regjsgen "^0.5.0" + regjsparser "^0.6.0" + unicode-match-property-ecmascript "^1.0.4" + unicode-match-property-value-ecmascript "^1.1.0" + registry-auth-token@^3.0.1: version "3.3.2" resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-3.3.2.tgz#851fd49038eecb586911115af845260eec983f20" From e89ec97f46b924299388ffedd967cc3381bb2738 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 25 Sep 2019 09:59:01 +0000 Subject: [PATCH 11/62] chore(deps): update node.js to v10.16.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 97850eb9..9d56b667 100644 --- a/package.json +++ b/package.json @@ -140,7 +140,7 @@ ] }, "volta": { - "node": "10.16.0", + "node": "10.16.3", "yarn": "1.16.0" }, "collective": { From 8c0d178739117fe490f017221f1be75da4103f68 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 25 Sep 2019 11:26:17 +0000 Subject: [PATCH 12/62] chore(deps): update yarn to v1.17.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9d56b667..d8230f46 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ }, "volta": { "node": "10.16.3", - "yarn": "1.16.0" + "yarn": "1.17.3" }, "collective": { "type": "opencollective", From 23d6a5af785ddc5796a402fb41e24f680341e06e Mon Sep 17 00:00:00 2001 From: Ward Date: Thu, 26 Sep 2019 10:14:31 +0200 Subject: [PATCH 13/62] fix: useDebounce remove deps from function arguments (#623) --- src/useDebounce.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/useDebounce.ts b/src/useDebounce.ts index 3c7d4664..bb7bffb7 100644 --- a/src/useDebounce.ts +++ b/src/useDebounce.ts @@ -1,14 +1,14 @@ +import { DependencyList } from 'react'; import useUpdateEffect from './useUpdateEffect'; -const useDebounce = (fn: () => any, ms: number = 0, args: any[] = []) => { +const useDebounce = (fn: () => any, ms: number = 0, deps: DependencyList = []) => { useUpdateEffect(() => { - const handle = setTimeout(fn.bind(null, args), ms); + const timeout = setTimeout(fn, ms); return () => { - // if args change then clear timeout - clearTimeout(handle); + clearTimeout(timeout); }; - }, args); + }, deps); }; export default useDebounce; From b5700f2664b922b58dae193c1cf9427059570a9c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 26 Sep 2019 08:16:24 +0000 Subject: [PATCH 14/62] chore(release): 12.2.2 [skip ci] ## [12.2.2](https://github.com/streamich/react-use/compare/v12.2.1...v12.2.2) (2019-09-26) ### Bug Fixes * useDebounce remove deps from function arguments ([#623](https://github.com/streamich/react-use/issues/623)) ([23d6a5a](https://github.com/streamich/react-use/commit/23d6a5a)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d0dd3eb..f71bdd3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [12.2.2](https://github.com/streamich/react-use/compare/v12.2.1...v12.2.2) (2019-09-26) + + +### Bug Fixes + +* useDebounce remove deps from function arguments ([#623](https://github.com/streamich/react-use/issues/623)) ([23d6a5a](https://github.com/streamich/react-use/commit/23d6a5a)) + ## [12.2.1](https://github.com/streamich/react-use/compare/v12.2.0...v12.2.1) (2019-09-23) diff --git a/package.json b/package.json index d8230f46..c74199d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-use", - "version": "12.2.1", + "version": "12.2.2", "description": "Collection of React Hooks", "main": "lib/index.js", "module": "esm/index.js", From 6768efe887100e25acea598eb18a05e812b8ef55 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 26 Sep 2019 10:38:45 +0000 Subject: [PATCH 15/62] chore(deps): update dependency lint-staged to v9.4.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c74199d3..301498c7 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "husky": "3.0.5", "jest": "24.9.0", "keyboardjs": "2.5.1", - "lint-staged": "9.3.0", + "lint-staged": "9.4.0", "markdown-loader": "5.1.0", "prettier": "1.18.2", "raf-stub": "3.0.0", diff --git a/yarn.lock b/yarn.lock index cccb45ef..e904ee39 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7971,10 +7971,10 @@ lines-and-columns@^1.1.6: resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= -lint-staged@9.3.0: - version "9.3.0" - resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.3.0.tgz#522a79f166050ab5777887348f2cbdb03f71acac" - integrity sha512-OuL3xo6XpBErl16+3W9PdnFmgeGp12lM8I1Ii/B56S8Edy1kyrf4W8VD4IBn9v17QlutRQEWUJ54YF/VVQ7J2A== +lint-staged@9.4.0: + version "9.4.0" + resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.4.0.tgz#dd4abcc9a82539fd290aed1584e3241b8f8af687" + integrity sha512-jTu1KoGiGTSffM539wK+3igVqDGVsby3KwDBaXL471YndahkjnavLX+R5Nsk49JwklyMo0ZAXay1BaoyA6d2Jw== dependencies: chalk "^2.4.2" commander "^2.20.0" From d3136b9dbab3e7023197449a9e8383cb0d5c6452 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 27 Sep 2019 20:39:31 +0000 Subject: [PATCH 16/62] chore(deps): update react monorepo to v16.10.0 --- package.json | 6 +++--- yarn.lock | 50 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 301498c7..887b060f 100644 --- a/package.json +++ b/package.json @@ -89,11 +89,11 @@ "markdown-loader": "5.1.0", "prettier": "1.18.2", "raf-stub": "3.0.0", - "react": "16.9.0", - "react-dom": "16.9.0", + "react": "16.10.0", + "react-dom": "16.10.0", "react-frame-component": "4.1.1", "react-spring": "8.0.27", - "react-test-renderer": "16.9.0", + "react-test-renderer": "16.10.0", "rebound": "0.1.0", "redux-logger": "3.0.6", "redux-thunk": "2.3.0", diff --git a/yarn.lock b/yarn.lock index e904ee39..ad3110ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10338,7 +10338,17 @@ react-docgen@^4.1.0: node-dir "^0.1.10" recast "^0.17.3" -react-dom@16.9.0, react-dom@^16.8.3: +react-dom@16.10.0: + version "16.10.0" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.10.0.tgz#319356767b5c044f3c016eef28518ef7726dce84" + integrity sha512-0QJQUFrKG04hB/1lWyUs/FOd1qNseKGRQI+JBRsADIqVAFxYObhZ2zsVQKjt+nVSCmi8KA0sL52RLwwWuXQtOw== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + prop-types "^15.6.2" + scheduler "^0.16.0" + +react-dom@^16.8.3: version "16.9.0" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.9.0.tgz#5e65527a5e26f22ae3701131bcccaee9fb0d3962" integrity sha512-YFT2rxO9hM70ewk9jq0y6sQk8cL02xm4+IzYBz75CQGlClQQ1Bxq0nhHF6OtSbit+AIahujJgb/CPRibFkMNJQ== @@ -10415,11 +10425,16 @@ react-inspector@^3.0.2: is-dom "^1.0.9" prop-types "^15.6.1" -react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.9.0: +react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4: version "16.9.0" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb" integrity sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw== +react-is@^16.8.6: + version "16.10.0" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.10.0.tgz#3d6a031e57fff73c3cfa0347feb3e8f40c5141e5" + integrity sha512-WRki2sBb7MTpYp7FtDEmSeGKX2vamYyq3rc9o7fKUG+/DHVyJu69NnvJsiSwwhh2Tt8XN40MQHkDBEXwyfxncQ== + react-lifecycles-compat@^3.0.2, react-lifecycles-compat@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" @@ -10488,15 +10503,15 @@ react-syntax-highlighter@^8.0.1: prismjs "^1.8.4" refractor "^2.4.1" -react-test-renderer@16.9.0: - version "16.9.0" - resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.9.0.tgz#7ed657a374af47af88f66f33a3ef99c9610c8ae9" - integrity sha512-R62stB73qZyhrJo7wmCW9jgl/07ai+YzvouvCXIJLBkRlRqLx4j9RqcLEAfNfU3OxTGucqR2Whmn3/Aad6L3hQ== +react-test-renderer@16.10.0: + version "16.10.0" + resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.10.0.tgz#33dddd71e4f43d58a4e1dfa332d4b8e683084baf" + integrity sha512-lO8zoAWiEpNKfQvup7b36gsVwcPJxswL9a6IrVloOHwvsB6bhrlQVYH4Wqfhhp/oXOyDNvPnQU1g6xLglPqAJA== dependencies: object-assign "^4.1.1" prop-types "^15.6.2" - react-is "^16.9.0" - scheduler "^0.15.0" + react-is "^16.8.6" + scheduler "^0.16.0" react-textarea-autosize@^7.1.0: version "7.1.0" @@ -10521,7 +10536,16 @@ react-wait@^0.3.0: resolved "https://registry.yarnpkg.com/react-wait/-/react-wait-0.3.0.tgz#0cdd4d919012451a5bc3ab0a16d00c6fd9a8c10b" integrity sha512-kB5x/kMKWcn0uVr9gBdNz21/oGbQwEQnF3P9p6E9yLfJ9DRcKS0fagbgYMFI0YFOoyKDj+2q6Rwax0kTYJF37g== -react@16.9.0, react@^16.8.3: +react@16.10.0: + version "16.10.0" + resolved "https://registry.yarnpkg.com/react/-/react-16.10.0.tgz#95c41e8fc1c706e174deef54b663b5ab94c8ee32" + integrity sha512-lc37bD3j6ZWJRso/a1rrFu6CO1qOf30ZadUDBi1c5RHA1lBSWA8x2MGABB6Oikk+RfmgC+kAT+XegL0eD1ecKg== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + prop-types "^15.6.2" + +react@^16.8.3: version "16.9.0" resolved "https://registry.yarnpkg.com/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa" integrity sha512-+7LQnFBwkiw+BobzOF6N//BdoNw0ouwmSJTEm9cglOOmsg/TMiFHZLe2sEoN5M7LgJTj9oHH0gxklfnQe66S1w== @@ -11191,6 +11215,14 @@ scheduler@^0.15.0: loose-envify "^1.1.0" object-assign "^4.1.1" +scheduler@^0.16.0: + version "0.16.0" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.16.0.tgz#cc8914b79c5c1cfa16714cb1ddc4cbd2c7513efa" + integrity sha512-Jq59uCXQzi71B562VEjuDgvsgfTfkLDvdjNhA7hamN/fKBxecXIEFF24Zu4OVrnAz9NJJ8twa9X16Zp4b0P/xQ== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + schema-utils@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-1.0.0.tgz#0b79a93204d7b600d4b2850d1f66c2a34951c770" From 18402ce5143e4d2ebed62976af28a2d92324c6a1 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sat, 28 Sep 2019 01:03:47 +0000 Subject: [PATCH 17/62] chore(deps): update dependency husky to v3.0.6 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 887b060f..a07435d3 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "babel-plugin-dynamic-import-node": "2.3.0", "fork-ts-checker-webpack-plugin": "1.5.0", "gh-pages": "2.1.1", - "husky": "3.0.5", + "husky": "3.0.6", "jest": "24.9.0", "keyboardjs": "2.5.1", "lint-staged": "9.4.0", diff --git a/yarn.lock b/yarn.lock index ad3110ae..6d743b5b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6511,10 +6511,10 @@ humanize-url@^1.0.0: normalize-url "^1.0.0" strip-url-auth "^1.0.0" -husky@3.0.5: - version "3.0.5" - resolved "https://registry.yarnpkg.com/husky/-/husky-3.0.5.tgz#d7db27c346645a8dc52df02aa534a377ad7925e0" - integrity sha512-cKd09Jy9cDyNIvAdN2QQAP/oA21sle4FWXjIMDttailpLAYZuBE7WaPmhrkj+afS8Sj9isghAtFvWSQ0JiwOHg== +husky@3.0.6: + version "3.0.6" + resolved "https://registry.yarnpkg.com/husky/-/husky-3.0.6.tgz#035aa2c0ae992a131fc72fcb410f1758daad1147" + integrity sha512-bNTgujuC5VS0m8gK70zRpzXq9rccFUFcjuU6L/SFLZxV7eke+6x10Tpk+st3rmgCEsQ4vn+yJk1jx3gvSD8knQ== dependencies: chalk "^2.4.2" cosmiconfig "^5.2.1" From 0330664e9f81dd47fa9379e8bb748fa593a427c1 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sat, 28 Sep 2019 01:53:24 +0000 Subject: [PATCH 18/62] chore(deps): update dependency husky to v3.0.7 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a07435d3..bd952ea7 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "babel-plugin-dynamic-import-node": "2.3.0", "fork-ts-checker-webpack-plugin": "1.5.0", "gh-pages": "2.1.1", - "husky": "3.0.6", + "husky": "3.0.7", "jest": "24.9.0", "keyboardjs": "2.5.1", "lint-staged": "9.4.0", diff --git a/yarn.lock b/yarn.lock index 6d743b5b..584fee59 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6511,10 +6511,10 @@ humanize-url@^1.0.0: normalize-url "^1.0.0" strip-url-auth "^1.0.0" -husky@3.0.6: - version "3.0.6" - resolved "https://registry.yarnpkg.com/husky/-/husky-3.0.6.tgz#035aa2c0ae992a131fc72fcb410f1758daad1147" - integrity sha512-bNTgujuC5VS0m8gK70zRpzXq9rccFUFcjuU6L/SFLZxV7eke+6x10Tpk+st3rmgCEsQ4vn+yJk1jx3gvSD8knQ== +husky@3.0.7: + version "3.0.7" + resolved "https://registry.yarnpkg.com/husky/-/husky-3.0.7.tgz#05e869006c7d9a31b27893aeda520e730bd125b9" + integrity sha512-fIrkaREoQk6DO8KnSX16Aq7Kg9SxqYYQZH/9b+4AxXyXNNgpJLsc8lWlQCShLus1nbujIyZ/WQZBHGwClohK/w== dependencies: chalk "^2.4.2" cosmiconfig "^5.2.1" From a0b3a420f7256118ecf9477d23b5edacb901f43e Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sat, 28 Sep 2019 16:42:51 +0000 Subject: [PATCH 19/62] chore(deps): update yarn to v1.19.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd952ea7..35e9ee38 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ }, "volta": { "node": "10.16.3", - "yarn": "1.17.3" + "yarn": "1.19.0" }, "collective": { "type": "opencollective", From 1d433aec89636b497703caed825e14c8b2af2d7a Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sat, 28 Sep 2019 18:36:10 +0000 Subject: [PATCH 20/62] chore(deps): update react monorepo to v16.10.1 --- package.json | 6 +++--- yarn.lock | 36 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 35e9ee38..ca94cd36 100644 --- a/package.json +++ b/package.json @@ -89,11 +89,11 @@ "markdown-loader": "5.1.0", "prettier": "1.18.2", "raf-stub": "3.0.0", - "react": "16.10.0", - "react-dom": "16.10.0", + "react": "16.10.1", + "react-dom": "16.10.1", "react-frame-component": "4.1.1", "react-spring": "8.0.27", - "react-test-renderer": "16.10.0", + "react-test-renderer": "16.10.1", "rebound": "0.1.0", "redux-logger": "3.0.6", "redux-thunk": "2.3.0", diff --git a/yarn.lock b/yarn.lock index 584fee59..9a45628f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10338,15 +10338,15 @@ react-docgen@^4.1.0: node-dir "^0.1.10" recast "^0.17.3" -react-dom@16.10.0: - version "16.10.0" - resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.10.0.tgz#319356767b5c044f3c016eef28518ef7726dce84" - integrity sha512-0QJQUFrKG04hB/1lWyUs/FOd1qNseKGRQI+JBRsADIqVAFxYObhZ2zsVQKjt+nVSCmi8KA0sL52RLwwWuXQtOw== +react-dom@16.10.1: + version "16.10.1" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.10.1.tgz#479a6511ba34a429273c213cbc2a9ac4d296dac1" + integrity sha512-SmM4ZW0uug0rn95U8uqr52I7UdNf6wdGLeXDmNLfg3y5q5H9eAbdjF5ubQc3bjDyRrvdAB2IKG7X0GzSpnn5Mg== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" prop-types "^15.6.2" - scheduler "^0.16.0" + scheduler "^0.16.1" react-dom@^16.8.3: version "16.9.0" @@ -10503,15 +10503,15 @@ react-syntax-highlighter@^8.0.1: prismjs "^1.8.4" refractor "^2.4.1" -react-test-renderer@16.10.0: - version "16.10.0" - resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.10.0.tgz#33dddd71e4f43d58a4e1dfa332d4b8e683084baf" - integrity sha512-lO8zoAWiEpNKfQvup7b36gsVwcPJxswL9a6IrVloOHwvsB6bhrlQVYH4Wqfhhp/oXOyDNvPnQU1g6xLglPqAJA== +react-test-renderer@16.10.1: + version "16.10.1" + resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.10.1.tgz#75b8e8ce152e00eadd303e9fa514a2ca917ee049" + integrity sha512-VT8nd7XrrUV7MQPxeIuH7WstfrK2A8kgcMwGUtVXa0ja+CiYkxdmLYNjwX1L7irRF7ydzJJWiSLsQf2xBj4Xaw== dependencies: object-assign "^4.1.1" prop-types "^15.6.2" react-is "^16.8.6" - scheduler "^0.16.0" + scheduler "^0.16.1" react-textarea-autosize@^7.1.0: version "7.1.0" @@ -10536,10 +10536,10 @@ react-wait@^0.3.0: resolved "https://registry.yarnpkg.com/react-wait/-/react-wait-0.3.0.tgz#0cdd4d919012451a5bc3ab0a16d00c6fd9a8c10b" integrity sha512-kB5x/kMKWcn0uVr9gBdNz21/oGbQwEQnF3P9p6E9yLfJ9DRcKS0fagbgYMFI0YFOoyKDj+2q6Rwax0kTYJF37g== -react@16.10.0: - version "16.10.0" - resolved "https://registry.yarnpkg.com/react/-/react-16.10.0.tgz#95c41e8fc1c706e174deef54b663b5ab94c8ee32" - integrity sha512-lc37bD3j6ZWJRso/a1rrFu6CO1qOf30ZadUDBi1c5RHA1lBSWA8x2MGABB6Oikk+RfmgC+kAT+XegL0eD1ecKg== +react@16.10.1: + version "16.10.1" + resolved "https://registry.yarnpkg.com/react/-/react-16.10.1.tgz#967c1e71a2767dfa699e6ba702a00483e3b0573f" + integrity sha512-2bisHwMhxQ3XQz4LiJJwG3360pY965pTl/MRrZYxIBKVj4fOHoDs5aZAkYXGxDRO1Li+SyjTAilQEbOmtQJHzA== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" @@ -11215,10 +11215,10 @@ scheduler@^0.15.0: loose-envify "^1.1.0" object-assign "^4.1.1" -scheduler@^0.16.0: - version "0.16.0" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.16.0.tgz#cc8914b79c5c1cfa16714cb1ddc4cbd2c7513efa" - integrity sha512-Jq59uCXQzi71B562VEjuDgvsgfTfkLDvdjNhA7hamN/fKBxecXIEFF24Zu4OVrnAz9NJJ8twa9X16Zp4b0P/xQ== +scheduler@^0.16.1: + version "0.16.1" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.16.1.tgz#a6fb6ddec12dc2119176e6eb54ecfe69a9eba8df" + integrity sha512-MIuie7SgsqMYOdCXVFZa8SKoNorJZUWHW8dPgto7uEHn1lX3fg2Gu0TzgK8USj76uxV7vB5eRMnZs/cdEHg+cg== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" From b061465b1051cc3690fa2b13380d1a7bc4af15a4 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sun, 29 Sep 2019 06:35:56 +0000 Subject: [PATCH 21/62] chore(deps): update dependency ts-loader to v6.2.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ca94cd36..87fe9bc4 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "rimraf": "3.0.0", "rxjs": "6.5.3", "semantic-release": "15.13.24", - "ts-loader": "6.1.2", + "ts-loader": "6.2.0", "ts-node": "8.4.1", "tslint": "5.20.0", "tslint-config-prettier": "1.18.0", diff --git a/yarn.lock b/yarn.lock index 9a45628f..a294fd83 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12402,10 +12402,10 @@ ts-easing@^0.2.0: resolved "https://registry.yarnpkg.com/ts-easing/-/ts-easing-0.2.0.tgz#c8a8a35025105566588d87dbda05dd7fbfa5a4ec" integrity sha512-Z86EW+fFFh/IFB1fqQ3/+7Zpf9t2ebOAxNI/V6Wo7r5gqiqtxmgTlQ1qbqQcjLKYeSHPTsEmvlJUDg/EuL0uHQ== -ts-loader@6.1.2: - version "6.1.2" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-6.1.2.tgz#ff6bc767334970226438949fbde2e211147a1325" - integrity sha512-dudxFKm0Ellrg/gLNlu+97/UgwvoMK0SdUVImPUSzq3IcRUVtShylZvcMX+CgvCQL1BEKb913NL0gAP1GA/OFw== +ts-loader@6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-6.2.0.tgz#52d3993ecbc5474c1513242388e1049da0fce880" + integrity sha512-Da8h3fD+HiZ9GvZJydqzk3mTC9nuOKYlJcpuk+Zv6Y1DPaMvBL+56GRzZFypx2cWrZFMsQr869+Ua2slGoLxvQ== dependencies: chalk "^2.3.0" enhanced-resolve "^4.0.0" From 7f3f7bec81fa6e8b44acb60c61a81f0eca284ad7 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 1 Oct 2019 05:24:18 +0000 Subject: [PATCH 22/62] chore(deps): update dependency lint-staged to v9.4.1 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 87fe9bc4..d67082a7 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "husky": "3.0.7", "jest": "24.9.0", "keyboardjs": "2.5.1", - "lint-staged": "9.4.0", + "lint-staged": "9.4.1", "markdown-loader": "5.1.0", "prettier": "1.18.2", "raf-stub": "3.0.0", diff --git a/yarn.lock b/yarn.lock index a294fd83..163790c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7971,10 +7971,10 @@ lines-and-columns@^1.1.6: resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= -lint-staged@9.4.0: - version "9.4.0" - resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.4.0.tgz#dd4abcc9a82539fd290aed1584e3241b8f8af687" - integrity sha512-jTu1KoGiGTSffM539wK+3igVqDGVsby3KwDBaXL471YndahkjnavLX+R5Nsk49JwklyMo0ZAXay1BaoyA6d2Jw== +lint-staged@9.4.1: + version "9.4.1" + resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.4.1.tgz#60c0f85745bd398e6460aa7f5adb3cad3a2b862c" + integrity sha512-zFRbo1bAJEVf1m33paTTjDVfy2v3lICCqHfmQSgNoI+lWpi7HPG5y/R2Y7Whdce+FKxlZYs/U1sDSx8+nmQdDA== dependencies: chalk "^2.4.2" commander "^2.20.0" From 42b31b9e36f39c9cbe7fd8b042a525ca565b8555 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 2 Oct 2019 01:46:15 +0000 Subject: [PATCH 23/62] chore(deps): update dependency husky to v3.0.8 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d67082a7..f43f343b 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "babel-plugin-dynamic-import-node": "2.3.0", "fork-ts-checker-webpack-plugin": "1.5.0", "gh-pages": "2.1.1", - "husky": "3.0.7", + "husky": "3.0.8", "jest": "24.9.0", "keyboardjs": "2.5.1", "lint-staged": "9.4.1", diff --git a/yarn.lock b/yarn.lock index 163790c1..9fd0edde 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6511,10 +6511,10 @@ humanize-url@^1.0.0: normalize-url "^1.0.0" strip-url-auth "^1.0.0" -husky@3.0.7: - version "3.0.7" - resolved "https://registry.yarnpkg.com/husky/-/husky-3.0.7.tgz#05e869006c7d9a31b27893aeda520e730bd125b9" - integrity sha512-fIrkaREoQk6DO8KnSX16Aq7Kg9SxqYYQZH/9b+4AxXyXNNgpJLsc8lWlQCShLus1nbujIyZ/WQZBHGwClohK/w== +husky@3.0.8: + version "3.0.8" + resolved "https://registry.yarnpkg.com/husky/-/husky-3.0.8.tgz#8de3fed26ce9b43034ef51013c4ad368b6b74ea8" + integrity sha512-HFOsgcyrX3qe/rBuqyTt+P4Gxn5P0seJmr215LAZ/vnwK3jWB3r0ck7swbzGRUbufCf9w/lgHPVbF/YXQALgfQ== dependencies: chalk "^2.4.2" cosmiconfig "^5.2.1" From a0eebfe70ad4910b2e2f4c49ffe45f06b9c9d9cc Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 3 Oct 2019 19:37:45 +0000 Subject: [PATCH 24/62] chore(deps): update dependency @testing-library/react-hooks to v2.0.3 --- package.json | 2 +- yarn.lock | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index f43f343b..94b92d0c 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "@storybook/addon-notes": "5.1.11", "@storybook/addon-options": "5.1.11", "@storybook/react": "5.1.11", - "@testing-library/react-hooks": "2.0.1", + "@testing-library/react-hooks": "2.0.3", "@types/jest": "24.0.18", "@types/react": "16.9.2", "babel-core": "6.26.3", diff --git a/yarn.lock b/yarn.lock index 9fd0edde..8e605bb0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2108,14 +2108,13 @@ "@svgr/plugin-svgo" "^4.3.1" loader-utils "^1.2.3" -"@testing-library/react-hooks@2.0.1": - version "2.0.1" - resolved "https://registry.yarnpkg.com/@testing-library/react-hooks/-/react-hooks-2.0.1.tgz#1c3ec40882d0830df3078ddae0056fdf7366c81d" - integrity sha512-MLTvWX7/csq/uQzP4WJntGz0QJDq6H4EzjV0VTL5YJE7KBZbaQ9DGT0IbtjuB33L4R4YKZ55rGZQ5eL+WiZtQA== +"@testing-library/react-hooks@2.0.3": + version "2.0.3" + resolved "https://registry.yarnpkg.com/@testing-library/react-hooks/-/react-hooks-2.0.3.tgz#305a6c76facb5fa1d185792b9eb11b1ca1b63fb7" + integrity sha512-adm+7b1gcysGka8VuYq/ObBrIBJTT9QmCEIqPpuxozWFfVDgxSbzBGc44ia/WYLGVt2dqFIOc6/DmAmu/pa0gQ== dependencies: "@babel/runtime" "^7.5.4" - "@types/react" ">=16.9.0" - "@types/react-test-renderer" ">=16.9.0" + "@types/testing-library__react-hooks" "^2.0.0" "@types/babel__core@^7.1.0": version "7.1.0" @@ -2221,7 +2220,7 @@ resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.2.tgz#690a1475b84f2a884fd07cd797c00f5f31356ea8" integrity sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw== -"@types/react-test-renderer@>=16.9.0": +"@types/react-test-renderer@*": version "16.9.0" resolved "https://registry.yarnpkg.com/@types/react-test-renderer/-/react-test-renderer-16.9.0.tgz#d60f530ecf4c906721511603cca711b4fa830d41" integrity sha512-bN5EyjtuTY35xX7N5j0KP1vg5MpUXHpFTX6tGsqkNOthjNvet4VQOYRxFh+NT5cDSJrATmAFK9NLeYZ4mp/o0Q== @@ -2235,7 +2234,7 @@ dependencies: "@types/react" "*" -"@types/react@*", "@types/react@16.9.2", "@types/react@>=16.9.0": +"@types/react@*", "@types/react@16.9.2": version "16.9.2" resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.2.tgz#6d1765431a1ad1877979013906731aae373de268" integrity sha512-jYP2LWwlh+FTqGd9v7ynUKZzjj98T8x7Yclz479QdRhHfuW9yQ+0jjnD31eXSXutmBpppj5PYNLYLRfnZJvcfg== @@ -2248,6 +2247,14 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" integrity sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw== +"@types/testing-library__react-hooks@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@types/testing-library__react-hooks/-/testing-library__react-hooks-2.0.0.tgz#7b289d64945517ae8ba9cbcb0c5b282432aaeffa" + integrity sha512-YUVqXGCChJKEJ4aAnMXqPCq0NfPAFVsJeGIb2y/iiMjxwyu+45+vR+AHOwjJHHKEHeC0ZhOGrZ5gSEmaJe4tyQ== + dependencies: + "@types/react" "*" + "@types/react-test-renderer" "*" + "@types/yargs-parser@*": version "13.0.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-13.0.0.tgz#453743c5bbf9f1bed61d959baab5b06be029b2d0" From 29f07be8d5de5d2030bf868f78343b99160eebbd Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 3 Oct 2019 21:24:34 +0000 Subject: [PATCH 25/62] chore(deps): update react monorepo to v16.10.2 --- package.json | 6 +++--- yarn.lock | 36 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 94b92d0c..325195b1 100644 --- a/package.json +++ b/package.json @@ -89,11 +89,11 @@ "markdown-loader": "5.1.0", "prettier": "1.18.2", "raf-stub": "3.0.0", - "react": "16.10.1", - "react-dom": "16.10.1", + "react": "16.10.2", + "react-dom": "16.10.2", "react-frame-component": "4.1.1", "react-spring": "8.0.27", - "react-test-renderer": "16.10.1", + "react-test-renderer": "16.10.2", "rebound": "0.1.0", "redux-logger": "3.0.6", "redux-thunk": "2.3.0", diff --git a/yarn.lock b/yarn.lock index 8e605bb0..4117ee56 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10345,15 +10345,15 @@ react-docgen@^4.1.0: node-dir "^0.1.10" recast "^0.17.3" -react-dom@16.10.1: - version "16.10.1" - resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.10.1.tgz#479a6511ba34a429273c213cbc2a9ac4d296dac1" - integrity sha512-SmM4ZW0uug0rn95U8uqr52I7UdNf6wdGLeXDmNLfg3y5q5H9eAbdjF5ubQc3bjDyRrvdAB2IKG7X0GzSpnn5Mg== +react-dom@16.10.2: + version "16.10.2" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.10.2.tgz#4840bce5409176bc3a1f2bd8cb10b92db452fda6" + integrity sha512-kWGDcH3ItJK4+6Pl9DZB16BXYAZyrYQItU4OMy0jAkv5aNqc+mAKb4TpFtAteI6TJZu+9ZlNhaeNQSVQDHJzkw== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" prop-types "^15.6.2" - scheduler "^0.16.1" + scheduler "^0.16.2" react-dom@^16.8.3: version "16.9.0" @@ -10510,15 +10510,15 @@ react-syntax-highlighter@^8.0.1: prismjs "^1.8.4" refractor "^2.4.1" -react-test-renderer@16.10.1: - version "16.10.1" - resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.10.1.tgz#75b8e8ce152e00eadd303e9fa514a2ca917ee049" - integrity sha512-VT8nd7XrrUV7MQPxeIuH7WstfrK2A8kgcMwGUtVXa0ja+CiYkxdmLYNjwX1L7irRF7ydzJJWiSLsQf2xBj4Xaw== +react-test-renderer@16.10.2: + version "16.10.2" + resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.10.2.tgz#4d8492f8678c9b43b721a7d79ed0840fdae7c518" + integrity sha512-k9Qzyev6cTIcIfrhgrFlYQAFxh5EEDO6ALNqYqmKsWVA7Q/rUMTay5nD3nthi6COmYsd4ghVYyi8U86aoeMqYQ== dependencies: object-assign "^4.1.1" prop-types "^15.6.2" react-is "^16.8.6" - scheduler "^0.16.1" + scheduler "^0.16.2" react-textarea-autosize@^7.1.0: version "7.1.0" @@ -10543,10 +10543,10 @@ react-wait@^0.3.0: resolved "https://registry.yarnpkg.com/react-wait/-/react-wait-0.3.0.tgz#0cdd4d919012451a5bc3ab0a16d00c6fd9a8c10b" integrity sha512-kB5x/kMKWcn0uVr9gBdNz21/oGbQwEQnF3P9p6E9yLfJ9DRcKS0fagbgYMFI0YFOoyKDj+2q6Rwax0kTYJF37g== -react@16.10.1: - version "16.10.1" - resolved "https://registry.yarnpkg.com/react/-/react-16.10.1.tgz#967c1e71a2767dfa699e6ba702a00483e3b0573f" - integrity sha512-2bisHwMhxQ3XQz4LiJJwG3360pY965pTl/MRrZYxIBKVj4fOHoDs5aZAkYXGxDRO1Li+SyjTAilQEbOmtQJHzA== +react@16.10.2: + version "16.10.2" + resolved "https://registry.yarnpkg.com/react/-/react-16.10.2.tgz#a5ede5cdd5c536f745173c8da47bda64797a4cf0" + integrity sha512-MFVIq0DpIhrHFyqLU0S3+4dIcBhhOvBE8bJ/5kHPVOVaGdo0KuiQzpcjCPsf585WvhypqtrMILyoE2th6dT+Lw== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" @@ -11222,10 +11222,10 @@ scheduler@^0.15.0: loose-envify "^1.1.0" object-assign "^4.1.1" -scheduler@^0.16.1: - version "0.16.1" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.16.1.tgz#a6fb6ddec12dc2119176e6eb54ecfe69a9eba8df" - integrity sha512-MIuie7SgsqMYOdCXVFZa8SKoNorJZUWHW8dPgto7uEHn1lX3fg2Gu0TzgK8USj76uxV7vB5eRMnZs/cdEHg+cg== +scheduler@^0.16.2: + version "0.16.2" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.16.2.tgz#f74cd9d33eff6fc554edfb79864868e4819132c1" + integrity sha512-BqYVWqwz6s1wZMhjFvLfVR5WXP7ZY32M/wYPo04CcuPM7XZEbV2TBNW7Z0UkguPTl0dWMA59VbNXxK6q+pHItg== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" From 49372acaed8cefc4919afc3ff882f558ba617a26 Mon Sep 17 00:00:00 2001 From: Ward Oosterlijnck Date: Sat, 5 Oct 2019 16:02:42 +1000 Subject: [PATCH 26/62] fix: move react-wait types to dev dependencies, closes #644 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 325195b1..e6d9106d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ }, "homepage": "https://github.com/streamich/react-use#readme", "dependencies": { - "@types/react-wait": "^0.3.0", "copy-to-clipboard": "^3.1.0", "nano-css": "^5.1.0", "react-fast-compare": "^2.0.4", @@ -77,6 +76,7 @@ "@testing-library/react-hooks": "2.0.3", "@types/jest": "24.0.18", "@types/react": "16.9.2", + "@types/react-wait": "^0.3.0", "babel-core": "6.26.3", "babel-loader": "8.0.6", "babel-plugin-dynamic-import-node": "2.3.0", From 8a16c1de1cca20ea1663975f8f0498399ec08170 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sat, 5 Oct 2019 06:06:17 +0000 Subject: [PATCH 27/62] chore(release): 12.2.3 [skip ci] ## [12.2.3](https://github.com/streamich/react-use/compare/v12.2.2...v12.2.3) (2019-10-05) ### Bug Fixes * move react-wait types to dev dependencies, closes [#644](https://github.com/streamich/react-use/issues/644) ([49372ac](https://github.com/streamich/react-use/commit/49372ac)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f71bdd3d..8357ac04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [12.2.3](https://github.com/streamich/react-use/compare/v12.2.2...v12.2.3) (2019-10-05) + + +### Bug Fixes + +* move react-wait types to dev dependencies, closes [#644](https://github.com/streamich/react-use/issues/644) ([49372ac](https://github.com/streamich/react-use/commit/49372ac)) + ## [12.2.2](https://github.com/streamich/react-use/compare/v12.2.1...v12.2.2) (2019-09-26) diff --git a/package.json b/package.json index e6d9106d..b02d35fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-use", - "version": "12.2.2", + "version": "12.2.3", "description": "Collection of React Hooks", "main": "lib/index.js", "module": "esm/index.js", From a6afe924a0d1b0c13ffc5cbb2dc416bcad19fe42 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sat, 5 Oct 2019 06:04:51 +0000 Subject: [PATCH 28/62] chore(deps): pin dependency @types/react-wait to 0.3.0 --- package.json | 2 +- yarn.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b02d35fe..59674b5d 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@testing-library/react-hooks": "2.0.3", "@types/jest": "24.0.18", "@types/react": "16.9.2", - "@types/react-wait": "^0.3.0", + "@types/react-wait": "0.3.0", "babel-core": "6.26.3", "babel-loader": "8.0.6", "babel-plugin-dynamic-import-node": "2.3.0", diff --git a/yarn.lock b/yarn.lock index 4117ee56..68fad2ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2227,7 +2227,7 @@ dependencies: "@types/react" "*" -"@types/react-wait@^0.3.0": +"@types/react-wait@0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@types/react-wait/-/react-wait-0.3.0.tgz#6f7ef17571a17e72c7864ede8cf7d3aa525a005e" integrity sha512-5jIfDcHRjqeE7QfZG7kCqOpfrPSvOM1E3/nlKuJ/NZrG/WrhLo/AFr0i72jhTWzyNRo4ex0pshBaiCHksZXH3A== From ae6510550e177fcb6cda297cf6c6a2be9cb7a360 Mon Sep 17 00:00:00 2001 From: Jake Boone Date: Sat, 5 Oct 2019 19:05:50 -0700 Subject: [PATCH 29/62] chore(deps): update screenfull to v5.0.0 (#645) --- package.json | 2 +- src/useFullscreen.ts | 6 +++--- yarn.lock | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 59674b5d..be4bb824 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "react-fast-compare": "^2.0.4", "react-wait": "^0.3.0", "resize-observer-polyfill": "^1.5.1", - "screenfull": "^4.1.0", + "screenfull": "^5.0.0", "set-harmonic-interval": "^1.0.0", "throttle-debounce": "^2.0.1", "ts-easing": "^0.2.0" diff --git a/src/useFullscreen.ts b/src/useFullscreen.ts index 52f63705..afb754fd 100644 --- a/src/useFullscreen.ts +++ b/src/useFullscreen.ts @@ -26,7 +26,7 @@ const useFullscreen = (ref: RefObject, on: boolean, options: FullScreen }; const onChange = () => { - if (screenfull) { + if (screenfull.isEnabled) { const isScreenfullFullscreen = screenfull.isFullscreen; setIsFullscreen(isScreenfullFullscreen); if (!isScreenfullFullscreen) { @@ -35,7 +35,7 @@ const useFullscreen = (ref: RefObject, on: boolean, options: FullScreen } }; - if (screenfull && screenfull.enabled) { + if (screenfull.isEnabled) { try { screenfull.request(ref.current); setIsFullscreen(true); @@ -55,7 +55,7 @@ const useFullscreen = (ref: RefObject, on: boolean, options: FullScreen return () => { setIsFullscreen(false); - if (screenfull && screenfull.enabled) { + if (screenfull.isEnabled) { try { screenfull.off('change', onChange); screenfull.exit(); diff --git a/yarn.lock b/yarn.lock index 68fad2ee..64fb7c0a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11239,10 +11239,10 @@ schema-utils@^1.0.0: ajv-errors "^1.0.0" ajv-keywords "^3.1.0" -screenfull@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/screenfull/-/screenfull-4.1.0.tgz#30eb338f615941f5a2cdd96c14e36063d2d9d764" - integrity sha512-/qH0HAmc+ilbZ9Vf8J7RHjjecSdqmjIh98iMkA6uCSKcHdJK1TiXhTbR+cin8rG70xi4Peyz7wW1KJVP6sp30g== +screenfull@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/screenfull/-/screenfull-5.0.0.tgz#5c2010c0e84fd4157bf852877698f90b8cbe96f6" + integrity sha512-yShzhaIoE9OtOhWVyBBffA6V98CDCoyHTsp8228blmqYy1Z5bddzE/4FPiJKlr8DVR4VBiiUyfPzIQPIYDkeMA== scrollbarwidth@^0.1.3: version "0.1.3" From 529362e60f722742df0a24f6a75344fe52e07212 Mon Sep 17 00:00:00 2001 From: Arty Date: Sat, 5 Oct 2019 19:09:19 -0700 Subject: [PATCH 30/62] docs: useStateList demo link (#647) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f54afa21..81fe7ee9 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ - [`usePrevious`](./docs/usePrevious.md) — returns the previous state or props. - [`useObservable`](./docs/useObservable.md) — tracks latest value of an `Observable`. - [`useSetState`](./docs/useSetState.md) — creates `setState` method which works like `this.setState`. [![][img-demo]](https://codesandbox.io/s/n75zqn1xp0) - - [`useStateList`](./docs/useStateList.md) — circularly iterates over an array. + - [`useStateList`](./docs/useStateList.md) — circularly iterates over an array. [![][img-demo]](https://codesandbox.io/s/bold-dewdney-pjzkd) - [`useToggle` and `useBoolean`](./docs/useToggle.md) — tracks state of a boolean. - [`useCounter` and `useNumber`](./docs/useCounter.md) — tracks state of a number. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usecounter--demo) - [`useList`](./docs/useList.md) — tracks state of an array. From 9f003fda1c44efe72834cf098878655ac862f36b Mon Sep 17 00:00:00 2001 From: Arty Date: Sat, 5 Oct 2019 19:12:57 -0700 Subject: [PATCH 31/62] docs: usePrevious demo link (#651) --- README.md | 2 +- docs/usePrevious.md | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81fe7ee9..7f148986 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ - [`useDefault`](./docs/useDefault.md) — returns the default value when state is `null` or `undefined`. - [`useGetSet`](./docs/useGetSet.md) — returns state getter `get()` instead of raw state. - [`useGetSetState`](./docs/useGetSetState.md) — as if [`useGetSet`](./docs/useGetSet.md) and [`useSetState`](./docs/useSetState.md) had a baby. - - [`usePrevious`](./docs/usePrevious.md) — returns the previous state or props. + - [`usePrevious`](./docs/usePrevious.md) — returns the previous state or props. [![][img-demo]](https://codesandbox.io/s/fervent-galileo-krgx6) - [`useObservable`](./docs/useObservable.md) — tracks latest value of an `Observable`. - [`useSetState`](./docs/useSetState.md) — creates `setState` method which works like `this.setState`. [![][img-demo]](https://codesandbox.io/s/n75zqn1xp0) - [`useStateList`](./docs/useStateList.md) — circularly iterates over an array. [![][img-demo]](https://codesandbox.io/s/bold-dewdney-pjzkd) diff --git a/docs/usePrevious.md b/docs/usePrevious.md index 953dee14..76c49d4a 100644 --- a/docs/usePrevious.md +++ b/docs/usePrevious.md @@ -13,7 +13,11 @@ const Demo = () => { return (

- Now: {count}, before: {prevCount} + + +

+ Now: {count}, before: {prevCount} +

); }; From b1fc6a75a6e18a2a089cf7e55704414681ad85ad Mon Sep 17 00:00:00 2001 From: Arty Date: Sun, 6 Oct 2019 20:14:02 -0700 Subject: [PATCH 32/62] docs: useToggle demo link (#648) --- README.md | 2 +- docs/useToggle.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7f148986..166a8515 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ - [`useObservable`](./docs/useObservable.md) — tracks latest value of an `Observable`. - [`useSetState`](./docs/useSetState.md) — creates `setState` method which works like `this.setState`. [![][img-demo]](https://codesandbox.io/s/n75zqn1xp0) - [`useStateList`](./docs/useStateList.md) — circularly iterates over an array. [![][img-demo]](https://codesandbox.io/s/bold-dewdney-pjzkd) - - [`useToggle` and `useBoolean`](./docs/useToggle.md) — tracks state of a boolean. + - [`useToggle` and `useBoolean`](./docs/useToggle.md) — tracks state of a boolean. [![][img-demo]](https://codesandbox.io/s/focused-sammet-brw2d) - [`useCounter` and `useNumber`](./docs/useCounter.md) — tracks state of a number. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usecounter--demo) - [`useList`](./docs/useList.md) — tracks state of an array. - [`useMap`](./docs/useMap.md) — tracks state of an object. diff --git a/docs/useToggle.md b/docs/useToggle.md index e1a342e7..0405c6ce 100644 --- a/docs/useToggle.md +++ b/docs/useToggle.md @@ -7,7 +7,7 @@ React state hook that tracks value of a boolean. ## Usage ```jsx -import {useToggle, useBoolean} from 'react-use'; +import {useToggle} from 'react-use'; const Demo = () => { const [on, toggle] = useToggle(true); From c520797fd5756cb94892dfe87974ffb6f6b93d65 Mon Sep 17 00:00:00 2001 From: Arty Date: Sun, 6 Oct 2019 22:02:45 -0700 Subject: [PATCH 33/62] docs: useMap demo link + improved docs (#650) * improve docs: useMap demo link * improve docs: useMap demo link (remove callback usage added) * Add remove action to useMap story --- README.md | 2 +- docs/useMap.md | 14 ++++++++++---- src/__stories__/useMap.story.tsx | 7 +++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 166a8515..b8ffca34 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ - [`useToggle` and `useBoolean`](./docs/useToggle.md) — tracks state of a boolean. [![][img-demo]](https://codesandbox.io/s/focused-sammet-brw2d) - [`useCounter` and `useNumber`](./docs/useCounter.md) — tracks state of a number. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usecounter--demo) - [`useList`](./docs/useList.md) — tracks state of an array. - - [`useMap`](./docs/useMap.md) — tracks state of an object. + - [`useMap`](./docs/useMap.md) — tracks state of an object. [![][img-demo]](https://codesandbox.io/s/quirky-dewdney-gi161)
diff --git a/docs/useMap.md b/docs/useMap.md index 99e5e131..cf3273af 100644 --- a/docs/useMap.md +++ b/docs/useMap.md @@ -2,22 +2,28 @@ React state hook that tracks a value of an object. - ## Usage ```jsx import {useMap} from 'react-use'; const Demo = () => { - const [map, {set, reset}] = useMap({ + const [map, {set, remove, reset}] = useMap({ hello: 'there', }); return (
+ + +
{JSON.stringify(map, null, 2)}
- -
); }; diff --git a/src/__stories__/useMap.story.tsx b/src/__stories__/useMap.story.tsx index 83c2b95e..1e5d085f 100644 --- a/src/__stories__/useMap.story.tsx +++ b/src/__stories__/useMap.story.tsx @@ -4,15 +4,18 @@ import { useMap } from '..'; import ShowDocs from './util/ShowDocs'; const Demo = () => { - const [map, { set, reset }] = useMap({ + const [map, { set, remove, reset }] = useMap({ hello: 'there', }); return (
-
{JSON.stringify(map, null, 2)}
+ +
{JSON.stringify(map, null, 2)}
); }; From 4f4849412628ad063285d32b7bcd54d118ebfcec Mon Sep 17 00:00:00 2001 From: Arty Date: Sun, 6 Oct 2019 22:04:09 -0700 Subject: [PATCH 34/62] docs: useList demo link + improve docs (#649) * improve docs: useList demo link * improve docs: useList demo link (examples of callbacks usage) * Add all callback methods to useList story --- README.md | 2 +- docs/useList.md | 15 ++++++++++----- src/__stories__/useList.story.tsx | 14 ++++++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b8ffca34..5e1b99f7 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ - [`useStateList`](./docs/useStateList.md) — circularly iterates over an array. [![][img-demo]](https://codesandbox.io/s/bold-dewdney-pjzkd) - [`useToggle` and `useBoolean`](./docs/useToggle.md) — tracks state of a boolean. [![][img-demo]](https://codesandbox.io/s/focused-sammet-brw2d) - [`useCounter` and `useNumber`](./docs/useCounter.md) — tracks state of a number. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usecounter--demo) - - [`useList`](./docs/useList.md) — tracks state of an array. + - [`useList`](./docs/useList.md) — tracks state of an array. [![][img-demo]](https://codesandbox.io/s/wonderful-mahavira-1sm0w) - [`useMap`](./docs/useMap.md) — tracks state of an object. [![][img-demo]](https://codesandbox.io/s/quirky-dewdney-gi161) diff --git a/docs/useList.md b/docs/useList.md index 48b2c9a0..b2dad670 100644 --- a/docs/useList.md +++ b/docs/useList.md @@ -2,20 +2,25 @@ React state hook that tracks a value of an array. - ## Usage ```jsx import {useList} from 'react-use'; const Demo = () => { - const [list, {set, push}] = useList(); + const [list, { clear, filter, push, remove, set, sort, updateAt }] = useList(); return (
-
{list.join(',')}
- - + + + + + + + + +
{JSON.stringify(list, null, 2)}
); }; diff --git a/src/__stories__/useList.story.tsx b/src/__stories__/useList.story.tsx index 912552a2..f720447b 100644 --- a/src/__stories__/useList.story.tsx +++ b/src/__stories__/useList.story.tsx @@ -4,13 +4,19 @@ import { useList } from '..'; import ShowDocs from './util/ShowDocs'; const Demo = () => { - const [list, { set, push }] = useList(); + const [list, { clear, filter, push, remove, set, sort, updateAt }] = useList(); return (
-
{list.join(',')}
- - + + + + + + + + +
{JSON.stringify(list, null, 2)}
); }; From 03ccfa98459698b3d84dc65ec9bd6ad3ade1785a Mon Sep 17 00:00:00 2001 From: Ward Oosterlijnck Date: Mon, 7 Oct 2019 20:50:19 +1100 Subject: [PATCH 35/62] docs: add useUpsert to readme --- README.md | 2 +- docs/useList.md | 4 ++++ docs/useUpsert.md | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e1b99f7..3ba51e52 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ - [`useStateList`](./docs/useStateList.md) — circularly iterates over an array. [![][img-demo]](https://codesandbox.io/s/bold-dewdney-pjzkd) - [`useToggle` and `useBoolean`](./docs/useToggle.md) — tracks state of a boolean. [![][img-demo]](https://codesandbox.io/s/focused-sammet-brw2d) - [`useCounter` and `useNumber`](./docs/useCounter.md) — tracks state of a number. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usecounter--demo) - - [`useList`](./docs/useList.md) — tracks state of an array. [![][img-demo]](https://codesandbox.io/s/wonderful-mahavira-1sm0w) + - [`useList`](./docs/useList.md) and [`useUpsert`](./docs/useUpsert.md) — tracks state of an array. [![][img-demo]](https://codesandbox.io/s/wonderful-mahavira-1sm0w) - [`useMap`](./docs/useMap.md) — tracks state of an object. [![][img-demo]](https://codesandbox.io/s/quirky-dewdney-gi161) diff --git a/docs/useList.md b/docs/useList.md index b2dad670..e09709c9 100644 --- a/docs/useList.md +++ b/docs/useList.md @@ -25,3 +25,7 @@ const Demo = () => { ); }; ``` + +## Related hooks + +- [useUpsert](./useUpsert.md) diff --git a/docs/useUpsert.md b/docs/useUpsert.md index 2384660d..48c3de55 100644 --- a/docs/useUpsert.md +++ b/docs/useUpsert.md @@ -1,6 +1,7 @@ # `useUpsert` -Superset of `useList`. Provides an additional method to upsert (update or insert) an element into the list. +Superset of [`useList`](./useList.md). Provides an additional method to upsert (update or insert) an element into the list. + ## Usage ```jsx @@ -26,3 +27,7 @@ const Demo = () => { ); }; ``` + +## Related hooks + +- [useList](./useList.md) From 471da2aea3a413a9f6769db513e2aa4b7c759944 Mon Sep 17 00:00:00 2001 From: Ward Oosterlijnck Date: Mon, 7 Oct 2019 21:07:39 +1100 Subject: [PATCH 36/62] docs: useSearchParam warning about hash routers, closes #637 --- docs/useSearchParam.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/useSearchParam.md b/docs/useSearchParam.md index f1184676..6d9fe29c 100644 --- a/docs/useSearchParam.md +++ b/docs/useSearchParam.md @@ -2,7 +2,6 @@ React sensor hook that tracks browser's location search param. - ## Usage ```jsx @@ -27,3 +26,7 @@ const Demo = () => { ); }; ``` + +## Caveats/Gotchas + +When using a hash router, like `react-router`'s [``](https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/api/HashRouter.md), this hook won't be able to read the search parameters as they are considered part of the hash of the URL by browsers. From 9ea3548e4ca34cce659a4b266febfd8571fd53c6 Mon Sep 17 00:00:00 2001 From: Ward Date: Tue, 8 Oct 2019 08:30:21 +1100 Subject: [PATCH 37/62] feat: reset util callback for useList (#654) --- docs/useList.md | 5 ++-- src/__stories__/useList.story.tsx | 5 ++-- src/__tests__/useList.test.ts | 41 +++++++++++++++++++++++++++++++ src/useList.ts | 16 +++++++----- 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/docs/useList.md b/docs/useList.md index e09709c9..2e33e188 100644 --- a/docs/useList.md +++ b/docs/useList.md @@ -8,7 +8,7 @@ React state hook that tracks a value of an array. import {useList} from 'react-use'; const Demo = () => { - const [list, { clear, filter, push, remove, set, sort, updateAt }] = useList(); + const [list, { clear, filter, push, remove, set, sort, updateAt, reset }] = useList(); return (
@@ -19,7 +19,8 @@ const Demo = () => { - + +
{JSON.stringify(list, null, 2)}
); diff --git a/src/__stories__/useList.story.tsx b/src/__stories__/useList.story.tsx index f720447b..2ccfb611 100644 --- a/src/__stories__/useList.story.tsx +++ b/src/__stories__/useList.story.tsx @@ -4,7 +4,7 @@ import { useList } from '..'; import ShowDocs from './util/ShowDocs'; const Demo = () => { - const [list, { clear, filter, push, remove, set, sort, updateAt }] = useList(); + const [list, { clear, filter, push, remove, set, sort, updateAt, reset }] = useList([1, 2, 3, 4, 5]); return (
@@ -15,7 +15,8 @@ const Demo = () => { - + +
{JSON.stringify(list, null, 2)}
); diff --git a/src/__tests__/useList.test.ts b/src/__tests__/useList.test.ts index 047e6e68..f8dc9584 100644 --- a/src/__tests__/useList.test.ts +++ b/src/__tests__/useList.test.ts @@ -16,6 +16,7 @@ it('should init list and utils', () => { push: expect.any(Function), filter: expect.any(Function), sort: expect.any(Function), + reset: expect.any(Function), }); }); @@ -150,3 +151,43 @@ it('should sort current list by provided function', () => { expect(result.current[0]).toEqual(['March', 'Jan', 'Feb', 'Dec']); expect(result.current[0]).not.toBe(initList); // checking immutability }); + +it('should reset the list to initial list provided', () => { + const initList = [1, 2, 3]; + const { result } = setUp(initList); + const [, utils] = result.current; + + act(() => { + utils.push(4); + }); + + expect(result.current[0]).toEqual([1, 2, 3, 4]); + + act(() => { + utils.reset(); + }); + + expect(result.current[0]).toEqual([1, 2, 3]); + expect(result.current[0]).not.toBe(initList); // checking immutability +}); + +it('should memoized its utils methods', () => { + const initList = [1, 2, 3]; + const { result } = setUp(initList); + const [, utils] = result.current; + const { set, clear, updateAt, remove, push, filter, sort, reset } = utils; + + act(() => { + push(4); + }); + + expect(result.current[1]).toBe(utils); + expect(result.current[1].set).toBe(set); + expect(result.current[1].clear).toBe(clear); + expect(result.current[1].updateAt).toBe(updateAt); + expect(result.current[1].remove).toBe(remove); + expect(result.current[1].push).toBe(push); + expect(result.current[1].filter).toBe(filter); + expect(result.current[1].sort).toBe(sort); + expect(result.current[1].reset).toBe(reset); +}); diff --git a/src/useList.ts b/src/useList.ts index 5e292987..50000818 100644 --- a/src/useList.ts +++ b/src/useList.ts @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useMemo } from 'react'; export interface Actions { set: (list: T[]) => void; @@ -8,14 +8,14 @@ export interface Actions { push: (item: T) => void; filter: (fn: (value: T) => boolean) => void; sort: (fn?: (a: T, b: T) => number) => void; + reset: () => void; } const useList = (initialList: T[] = []): [T[], Actions] => { const [list, set] = useState(initialList); - return [ - list, - { + const utils = useMemo>( + () => ({ set, clear: () => set([]), updateAt: (index, entry) => @@ -24,8 +24,12 @@ const useList = (initialList: T[] = []): [T[], Actions] => { push: entry => set(currentList => [...currentList, entry]), filter: fn => set(currentList => currentList.filter(fn)), sort: (fn?) => set(currentList => [...currentList].sort(fn)), - }, - ]; + reset: () => set([...initialList]), + }), + [set] + ); + + return [list, utils]; }; export default useList; From 2ab1460c43d00c7b59ad1c6161dd325991ae85ac Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 7 Oct 2019 21:33:53 +0000 Subject: [PATCH 38/62] chore(release): 12.3.0 [skip ci] # [12.3.0](https://github.com/streamich/react-use/compare/v12.2.3...v12.3.0) (2019-10-07) ### Features * reset util callback for useList ([#654](https://github.com/streamich/react-use/issues/654)) ([9ea3548](https://github.com/streamich/react-use/commit/9ea3548)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8357ac04..6e84f524 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [12.3.0](https://github.com/streamich/react-use/compare/v12.2.3...v12.3.0) (2019-10-07) + + +### Features + +* reset util callback for useList ([#654](https://github.com/streamich/react-use/issues/654)) ([9ea3548](https://github.com/streamich/react-use/commit/9ea3548)) + ## [12.2.3](https://github.com/streamich/react-use/compare/v12.2.2...v12.2.3) (2019-10-05) diff --git a/package.json b/package.json index be4bb824..6b5b24c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-use", - "version": "12.2.3", + "version": "12.3.0", "description": "Collection of React Hooks", "main": "lib/index.js", "module": "esm/index.js", From c1484cbdfde1a7eea76adf7dd5fdc98b42ed38b6 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 8 Oct 2019 05:54:24 +0000 Subject: [PATCH 39/62] chore(deps): update dependency lint-staged to v9.4.2 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6b5b24c1..3a462360 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "husky": "3.0.8", "jest": "24.9.0", "keyboardjs": "2.5.1", - "lint-staged": "9.4.1", + "lint-staged": "9.4.2", "markdown-loader": "5.1.0", "prettier": "1.18.2", "raf-stub": "3.0.0", diff --git a/yarn.lock b/yarn.lock index 64fb7c0a..e1c3d4eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7978,10 +7978,10 @@ lines-and-columns@^1.1.6: resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= -lint-staged@9.4.1: - version "9.4.1" - resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.4.1.tgz#60c0f85745bd398e6460aa7f5adb3cad3a2b862c" - integrity sha512-zFRbo1bAJEVf1m33paTTjDVfy2v3lICCqHfmQSgNoI+lWpi7HPG5y/R2Y7Whdce+FKxlZYs/U1sDSx8+nmQdDA== +lint-staged@9.4.2: + version "9.4.2" + resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.4.2.tgz#14cb577a9512f520691f8b5aefce6a8f7ead6c04" + integrity sha512-OFyGokJSWTn2M6vngnlLXjaHhi8n83VIZZ5/1Z26SULRUWgR3ITWpAEQC9Pnm3MC/EpCxlwts/mQWDHNji2+zA== dependencies: chalk "^2.4.2" commander "^2.20.0" From b1944a1bdc84494737fd36b2e3229378da5d0d70 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 8 Oct 2019 12:23:39 +0000 Subject: [PATCH 40/62] chore(deps): update yarn to v1.19.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3a462360..46d408e6 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ }, "volta": { "node": "10.16.3", - "yarn": "1.19.0" + "yarn": "1.19.1" }, "collective": { "type": "opencollective", From 706f6607817c336a9324ea3fbee87661379bc909 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 8 Oct 2019 19:52:14 +0000 Subject: [PATCH 41/62] chore(deps): update babel monorepo to v7.6.3 --- package.json | 6 ++-- yarn.lock | 98 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 77 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 46d408e6..ef1fa6aa 100644 --- a/package.json +++ b/package.json @@ -60,10 +60,10 @@ "react-dom": "^16.8.0" }, "devDependencies": { - "@babel/core": "7.6.2", + "@babel/core": "7.6.3", "@babel/plugin-syntax-dynamic-import": "7.2.0", - "@babel/preset-env": "7.6.2", - "@babel/preset-react": "7.0.0", + "@babel/preset-env": "7.6.3", + "@babel/preset-react": "7.6.3", "@babel/preset-typescript": "7.6.0", "@semantic-release/changelog": "3.0.4", "@semantic-release/git": "7.0.16", diff --git a/yarn.lock b/yarn.lock index e1c3d4eb..5751c12d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -36,25 +36,25 @@ semver "^5.4.1" source-map "^0.5.0" -"@babel/core@7.6.2": - version "7.6.2" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.6.2.tgz#069a776e8d5e9eefff76236bc8845566bd31dd91" - integrity sha512-l8zto/fuoZIbncm+01p8zPSDZu/VuuJhAfA7d/AbzM09WR7iVhavvfNDYCNpo1VvLk6E6xgAoP9P+/EMJHuRkQ== +"@babel/core@7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.6.3.tgz#44de824e89eaa089bb12da7337bc9bdff2ab68f9" + integrity sha512-QfQ5jTBgXLzJuo7Mo8bZK/ePywmgNRgk/UQykiKwEtZPiFIn8ZqE6jB+AnD1hbB1S2xQyL4//it5vuAUOVAMTw== dependencies: "@babel/code-frame" "^7.5.5" - "@babel/generator" "^7.6.2" + "@babel/generator" "^7.6.3" "@babel/helpers" "^7.6.2" - "@babel/parser" "^7.6.2" + "@babel/parser" "^7.6.3" "@babel/template" "^7.6.0" - "@babel/traverse" "^7.6.2" - "@babel/types" "^7.6.0" + "@babel/traverse" "^7.6.3" + "@babel/types" "^7.6.3" convert-source-map "^1.1.0" debug "^4.1.0" json5 "^2.1.0" lodash "^4.17.13" resolve "^1.3.2" semver "^5.4.1" - source-map "^0.5.0" + source-map "^0.6.1" "@babel/core@^7.0.0", "@babel/core@^7.1.0", "@babel/core@^7.4.5": version "7.5.5" @@ -97,6 +97,16 @@ lodash "^4.17.13" source-map "^0.5.0" +"@babel/generator@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.6.3.tgz#71d5375264f93ec7bac7d9f35a67067733f5578e" + integrity sha512-hLhYbAb3pHwxjlijC4AQ7mqZdcoujiNaW7izCT04CIowHK8psN0IN8QjDv0iyFtycF5FowUOTwDloIheI25aMw== + dependencies: + "@babel/types" "^7.6.3" + jsesc "^2.5.1" + lodash "^4.17.13" + source-map "^0.6.1" + "@babel/helper-annotate-as-pure@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz#323d39dd0b50e10c7c06ca7d7638e6864d8c5c32" @@ -326,6 +336,11 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.6.2.tgz#205e9c95e16ba3b8b96090677a67c9d6075b70a1" integrity sha512-mdFqWrSPCmikBoaBYMuBulzTIKuXVPtEISFbRRVNwMWpCms/hmE2kRq0bblUHaNRKrjRlmVbx1sDHmjmRgD2Xg== +"@babel/parser@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.6.3.tgz#9eff8b9c3eeae16a74d8d4ff30da2bd0d6f0487e" + integrity sha512-sUZdXlva1dt2Vw2RqbMkmfoImubO0D0gaCrNngV6Hi0DA4x3o4mlrq0tbfY0dZEUIccH8I6wQ4qgEtwcpOR6Qg== + "@babel/plugin-proposal-async-generator-functions@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.2.0.tgz#b289b306669dce4ad20b0252889a15768c9d417e" @@ -512,10 +527,10 @@ "@babel/helper-plugin-utils" "^7.0.0" lodash "^4.17.13" -"@babel/plugin-transform-block-scoping@^7.6.2": - version "7.6.2" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.6.2.tgz#96c33ab97a9ae500cc6f5b19e04a7e6553360a79" - integrity sha512-zZT8ivau9LOQQaOGC7bQLQOT4XPkPXgN2ERfUgk1X8ql+mVkLc4E8eKk+FO3o0154kxzqenWCorfmEXpEZcrSQ== +"@babel/plugin-transform-block-scoping@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.6.3.tgz#6e854e51fbbaa84351b15d4ddafe342f3a5d542a" + integrity sha512-7hvrg75dubcO3ZI2rjYTzUrEuh1E9IyDEhhB6qfcooxhDA33xx2MasuLVgdxzcP6R/lipAC6n9ub9maNW6RKdw== dependencies: "@babel/helper-plugin-utils" "^7.0.0" lodash "^4.17.13" @@ -699,10 +714,10 @@ dependencies: regexp-tree "^0.1.6" -"@babel/plugin-transform-named-capturing-groups-regex@^7.6.2": - version "7.6.2" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.6.2.tgz#c1ca0bb84b94f385ca302c3932e870b0fb0e522b" - integrity sha512-xBdB+XOs+lgbZc2/4F5BVDVcDNS4tcSKQc96KmlqLEAwz6tpYPEvPdmDfvVG0Ssn8lAhronaRs6Z6KSexIpK5g== +"@babel/plugin-transform-named-capturing-groups-regex@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.6.3.tgz#aaa6e409dd4fb2e50b6e2a91f7e3a3149dbce0cf" + integrity sha512-jTkk7/uE6H2s5w6VlMHeWuH+Pcy2lmdwFoeWCVnvIrDUnB5gQqTVI8WfmEAhF2CDEarGrknZcmSFg1+bkfCoSw== dependencies: regexpu-core "^4.6.0" @@ -934,10 +949,10 @@ js-levenshtein "^1.1.3" semver "^5.5.0" -"@babel/preset-env@7.6.2": - version "7.6.2" - resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.6.2.tgz#abbb3ed785c7fe4220d4c82a53621d71fc0c75d3" - integrity sha512-Ru7+mfzy9M1/YTEtlDS8CD45jd22ngb9tXnn64DvQK3ooyqSw9K4K9DUWmYknTTVk4TqygL9dqCrZgm1HMea/Q== +"@babel/preset-env@7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.6.3.tgz#9e1bf05a2e2d687036d24c40e4639dc46cef2271" + integrity sha512-CWQkn7EVnwzlOdR5NOm2+pfgSNEZmvGjOhlCHBDq0J8/EStr+G+FvPEiz9B56dR6MoiUFjXhfE4hjLoAKKJtIQ== dependencies: "@babel/helper-module-imports" "^7.0.0" "@babel/helper-plugin-utils" "^7.0.0" @@ -955,7 +970,7 @@ "@babel/plugin-transform-arrow-functions" "^7.2.0" "@babel/plugin-transform-async-to-generator" "^7.5.0" "@babel/plugin-transform-block-scoped-functions" "^7.2.0" - "@babel/plugin-transform-block-scoping" "^7.6.2" + "@babel/plugin-transform-block-scoping" "^7.6.3" "@babel/plugin-transform-classes" "^7.5.5" "@babel/plugin-transform-computed-properties" "^7.2.0" "@babel/plugin-transform-destructuring" "^7.6.0" @@ -970,7 +985,7 @@ "@babel/plugin-transform-modules-commonjs" "^7.6.0" "@babel/plugin-transform-modules-systemjs" "^7.5.0" "@babel/plugin-transform-modules-umd" "^7.2.0" - "@babel/plugin-transform-named-capturing-groups-regex" "^7.6.2" + "@babel/plugin-transform-named-capturing-groups-regex" "^7.6.3" "@babel/plugin-transform-new-target" "^7.4.4" "@babel/plugin-transform-object-super" "^7.5.5" "@babel/plugin-transform-parameters" "^7.4.4" @@ -983,7 +998,7 @@ "@babel/plugin-transform-template-literals" "^7.4.4" "@babel/plugin-transform-typeof-symbol" "^7.2.0" "@babel/plugin-transform-unicode-regex" "^7.6.2" - "@babel/types" "^7.6.0" + "@babel/types" "^7.6.3" browserslist "^4.6.0" core-js-compat "^3.1.1" invariant "^2.2.2" @@ -1065,6 +1080,17 @@ "@babel/plugin-transform-react-jsx-self" "^7.0.0" "@babel/plugin-transform-react-jsx-source" "^7.0.0" +"@babel/preset-react@7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/preset-react/-/preset-react-7.6.3.tgz#d5242c828322520205ae4eda5d4f4f618964e2f6" + integrity sha512-07yQhmkZmRAfwREYIQgW0HEwMY9GBJVuPY4Q12UC72AbfaawuupVWa8zQs2tlL+yun45Nv/1KreII/0PLfEsgA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-transform-react-display-name" "^7.0.0" + "@babel/plugin-transform-react-jsx" "^7.0.0" + "@babel/plugin-transform-react-jsx-self" "^7.0.0" + "@babel/plugin-transform-react-jsx-source" "^7.0.0" + "@babel/preset-typescript@7.3.3": version "7.3.3" resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.3.3.tgz#88669911053fa16b2b276ea2ede2ca603b3f307a" @@ -1150,6 +1176,21 @@ globals "^11.1.0" lodash "^4.17.13" +"@babel/traverse@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.6.3.tgz#66d7dba146b086703c0fb10dd588b7364cec47f9" + integrity sha512-unn7P4LGsijIxaAJo/wpoU11zN+2IaClkQAxcJWBNCMS6cmVh802IyLHNkAjQ0iYnRS3nnxk5O3fuXW28IMxTw== + dependencies: + "@babel/code-frame" "^7.5.5" + "@babel/generator" "^7.6.3" + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-split-export-declaration" "^7.4.4" + "@babel/parser" "^7.6.3" + "@babel/types" "^7.6.3" + debug "^4.1.0" + globals "^11.1.0" + lodash "^4.17.13" + "@babel/types@^7.0.0", "@babel/types@^7.2.0", "@babel/types@^7.3.0", "@babel/types@^7.4.0", "@babel/types@^7.4.4", "@babel/types@^7.5.5": version "7.5.5" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.5.5.tgz#97b9f728e182785909aa4ab56264f090a028d18a" @@ -1168,6 +1209,15 @@ lodash "^4.17.13" to-fast-properties "^2.0.0" +"@babel/types@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.6.3.tgz#3f07d96f854f98e2fbd45c64b0cb942d11e8ba09" + integrity sha512-CqbcpTxMcpuQTMhjI37ZHVgjBkysg5icREQIEZ0eG1yCNwg3oy+5AaLiOKmjsCj6nqOsa6Hf0ObjRVwokb7srA== + dependencies: + esutils "^2.0.2" + lodash "^4.17.13" + to-fast-properties "^2.0.0" + "@cnakazawa/watch@^1.0.3": version "1.0.3" resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.3.tgz#099139eaec7ebf07a27c1786a3ff64f39464d2ef" From d1aaa855fc990d8bd47d66abe9b688e55d09557d Mon Sep 17 00:00:00 2001 From: Kevin Norris Date: Thu, 10 Oct 2019 23:29:01 +1300 Subject: [PATCH 42/62] tests: useFavicon (#666) --- src/__tests__/useFavicon.test.tsx | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/__tests__/useFavicon.test.tsx diff --git a/src/__tests__/useFavicon.test.tsx b/src/__tests__/useFavicon.test.tsx new file mode 100644 index 00000000..fcbbda43 --- /dev/null +++ b/src/__tests__/useFavicon.test.tsx @@ -0,0 +1,55 @@ +import { renderHook } from '@testing-library/react-hooks'; +import useFavicon from '../useFavicon'; + +afterEach(() => { + const favicon = document.querySelector("link[rel*='icon']"); + if (favicon) { + favicon.remove(); + } +}); + +describe('useFavicon', () => { + it('should be defined', () => { + expect(useFavicon).toBeDefined(); + }); + + it('should create a HTMLLinkElement', () => { + const faviconBeforeHook = document.querySelector("link[rel*='icon']"); + + expect(faviconBeforeHook).toBe(null); + renderHook(() => useFavicon('My-favicon')); + + const faviconAfterHook = document.querySelector("link[rel*='icon']"); + expect(faviconAfterHook).toBeInstanceOf(HTMLLinkElement); + }); + + it('should set the elements type to "image/x-icon"', () => { + renderHook(() => useFavicon('My-favicon')); + const favicon = document.querySelector("link[rel*='icon']") as HTMLLinkElement; + + expect(favicon.type).toBe('image/x-icon'); + }); + + it('should set the elements rel to "shortcut icon"', () => { + renderHook(() => useFavicon('My-favicon')); + const favicon = document.querySelector("link[rel*='icon']") as HTMLLinkElement; + + expect(favicon.rel).toBe('shortcut icon'); + }); + + it('should set the elements href to the provided string', () => { + renderHook(() => useFavicon('https://github.com/streamich/react-use')); + const favicon = document.querySelector("link[rel*='icon']") as HTMLLinkElement; + + expect(favicon.href).toBe('https://github.com/streamich/react-use'); + }); + + it('should update an existing favicon', () => { + const hook = renderHook(props => useFavicon(props), { initialProps: 'https://github.com/streamich/react-use' }); + const favicon = document.querySelector("link[rel*='icon']") as HTMLLinkElement; + + expect(favicon.href).toBe('https://github.com/streamich/react-use'); + hook.rerender('https://en.wikipedia.org/wiki/Favicon'); + expect(favicon.href).toBe('https://en.wikipedia.org/wiki/Favicon'); + }); +}); From 6bdd74e79cf9ff83ed1afd5cda3b62a90267e441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Kostrzewski?= Date: Thu, 10 Oct 2019 13:39:24 +0200 Subject: [PATCH 43/62] fix: move @types/react-wait to dependencies, closes #661 (#662) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ef1fa6aa..3049f985 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ }, "homepage": "https://github.com/streamich/react-use#readme", "dependencies": { + "@types/react-wait": "^0.3.0", "copy-to-clipboard": "^3.1.0", "nano-css": "^5.1.0", "react-fast-compare": "^2.0.4", @@ -76,7 +77,6 @@ "@testing-library/react-hooks": "2.0.3", "@types/jest": "24.0.18", "@types/react": "16.9.2", - "@types/react-wait": "0.3.0", "babel-core": "6.26.3", "babel-loader": "8.0.6", "babel-plugin-dynamic-import-node": "2.3.0", From 823f94f32190fe6728a829cfd895744f02878e66 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 10 Oct 2019 11:41:29 +0000 Subject: [PATCH 44/62] chore(release): 12.3.1 [skip ci] ## [12.3.1](https://github.com/streamich/react-use/compare/v12.3.0...v12.3.1) (2019-10-10) ### Bug Fixes * move [@types](https://github.com/types)/react-wait to dependencies, closes [#661](https://github.com/streamich/react-use/issues/661) ([#662](https://github.com/streamich/react-use/issues/662)) ([6bdd74e](https://github.com/streamich/react-use/commit/6bdd74e)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e84f524..17f4c954 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [12.3.1](https://github.com/streamich/react-use/compare/v12.3.0...v12.3.1) (2019-10-10) + + +### Bug Fixes + +* move [@types](https://github.com/types)/react-wait to dependencies, closes [#661](https://github.com/streamich/react-use/issues/661) ([#662](https://github.com/streamich/react-use/issues/662)) ([6bdd74e](https://github.com/streamich/react-use/commit/6bdd74e)) + # [12.3.0](https://github.com/streamich/react-use/compare/v12.2.3...v12.3.0) (2019-10-07) diff --git a/package.json b/package.json index 3049f985..89a4e6be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-use", - "version": "12.3.0", + "version": "12.3.1", "description": "Collection of React Hooks", "main": "lib/index.js", "module": "esm/index.js", From 655c49df85cad77c1b0a0149c76c360910fbff35 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 10 Oct 2019 14:29:59 +0000 Subject: [PATCH 45/62] chore(deps): update dependency @babel/core to v7.6.4 --- package.json | 2 +- yarn.lock | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 89a4e6be..54797164 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "react-dom": "^16.8.0" }, "devDependencies": { - "@babel/core": "7.6.3", + "@babel/core": "7.6.4", "@babel/plugin-syntax-dynamic-import": "7.2.0", "@babel/preset-env": "7.6.3", "@babel/preset-react": "7.6.3", diff --git a/yarn.lock b/yarn.lock index 5751c12d..60fc2e3b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -36,15 +36,15 @@ semver "^5.4.1" source-map "^0.5.0" -"@babel/core@7.6.3": - version "7.6.3" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.6.3.tgz#44de824e89eaa089bb12da7337bc9bdff2ab68f9" - integrity sha512-QfQ5jTBgXLzJuo7Mo8bZK/ePywmgNRgk/UQykiKwEtZPiFIn8ZqE6jB+AnD1hbB1S2xQyL4//it5vuAUOVAMTw== +"@babel/core@7.6.4": + version "7.6.4" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.6.4.tgz#6ebd9fe00925f6c3e177bb726a188b5f578088ff" + integrity sha512-Rm0HGw101GY8FTzpWSyRbki/jzq+/PkNQJ+nSulrdY6gFGOsNseCqD6KHRYe2E+EdzuBdr2pxCp6s4Uk6eJ+XQ== dependencies: "@babel/code-frame" "^7.5.5" - "@babel/generator" "^7.6.3" + "@babel/generator" "^7.6.4" "@babel/helpers" "^7.6.2" - "@babel/parser" "^7.6.3" + "@babel/parser" "^7.6.4" "@babel/template" "^7.6.0" "@babel/traverse" "^7.6.3" "@babel/types" "^7.6.3" @@ -54,7 +54,7 @@ lodash "^4.17.13" resolve "^1.3.2" semver "^5.4.1" - source-map "^0.6.1" + source-map "^0.5.0" "@babel/core@^7.0.0", "@babel/core@^7.1.0", "@babel/core@^7.4.5": version "7.5.5" @@ -107,6 +107,16 @@ lodash "^4.17.13" source-map "^0.6.1" +"@babel/generator@^7.6.4": + version "7.6.4" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.6.4.tgz#a4f8437287bf9671b07f483b76e3bb731bc97671" + integrity sha512-jsBuXkFoZxk0yWLyGI9llT9oiQ2FeTASmRFE32U+aaDTfoE92t78eroO7PTpU/OrYq38hlcDM6vbfLDaOLy+7w== + dependencies: + "@babel/types" "^7.6.3" + jsesc "^2.5.1" + lodash "^4.17.13" + source-map "^0.5.0" + "@babel/helper-annotate-as-pure@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz#323d39dd0b50e10c7c06ca7d7638e6864d8c5c32" @@ -341,6 +351,11 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.6.3.tgz#9eff8b9c3eeae16a74d8d4ff30da2bd0d6f0487e" integrity sha512-sUZdXlva1dt2Vw2RqbMkmfoImubO0D0gaCrNngV6Hi0DA4x3o4mlrq0tbfY0dZEUIccH8I6wQ4qgEtwcpOR6Qg== +"@babel/parser@^7.6.4": + version "7.6.4" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.6.4.tgz#cb9b36a7482110282d5cb6dd424ec9262b473d81" + integrity sha512-D8RHPW5qd0Vbyo3qb+YjO5nvUVRTXFLQ/FsDxJU2Nqz4uB5EnUN0ZQSEYpvTIbRuttig1XbHWU5oMeQwQSAA+A== + "@babel/plugin-proposal-async-generator-functions@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.2.0.tgz#b289b306669dce4ad20b0252889a15768c9d417e" @@ -2277,7 +2292,7 @@ dependencies: "@types/react" "*" -"@types/react-wait@0.3.0": +"@types/react-wait@^0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@types/react-wait/-/react-wait-0.3.0.tgz#6f7ef17571a17e72c7864ede8cf7d3aa525a005e" integrity sha512-5jIfDcHRjqeE7QfZG7kCqOpfrPSvOM1E3/nlKuJ/NZrG/WrhLo/AFr0i72jhTWzyNRo4ex0pshBaiCHksZXH3A== From b998f3d3974b7ea0d114f7bdd1c26a75a40ac09e Mon Sep 17 00:00:00 2001 From: xobotyi Date: Fri, 11 Oct 2019 03:59:06 +0300 Subject: [PATCH 46/62] useValidatableState -> useStateValidator; It is more suitable due to more flexible usage; --- ...lidatableState.md => useStateValidator.md} | 27 ++-- ...yState.story.tsx => useStateValidator.tsx} | 14 +- src/__tests__/useStateValidator.test.ts | 100 ++++++++++++++ src/__tests__/useValidatableState.test.ts | 126 ------------------ src/index.ts | 2 +- src/useStateValidator.ts | 36 +++++ src/useValidatableState.ts | 46 ------- 7 files changed, 157 insertions(+), 194 deletions(-) rename docs/{useValidatableState.md => useStateValidator.md} (50%) rename src/__stories__/{useValidityState.story.tsx => useStateValidator.tsx} (52%) create mode 100644 src/__tests__/useStateValidator.test.ts delete mode 100644 src/__tests__/useValidatableState.test.ts create mode 100644 src/useStateValidator.ts delete mode 100644 src/useValidatableState.ts diff --git a/docs/useValidatableState.md b/docs/useStateValidator.md similarity index 50% rename from docs/useValidatableState.md rename to docs/useStateValidator.md index 1c84449e..0b434fca 100644 --- a/docs/useValidatableState.md +++ b/docs/useStateValidator.md @@ -1,17 +1,17 @@ -# `useValidatableState` +# `useStateValidator` -Very similar to React's `useState` hook, but extended with validation functionality. -Each time state changes validator invoked and it's result stored to separate state. +Each time given state changes - validator function is invoked. ## Usage ```ts import * as React from 'react'; import { useCallback } from 'react'; -import { useValidatableState } from 'react-use'; +import { useStateValidator } from 'react-use'; +const DemoStateValidator = s => [s === '' ? null : (s * 1) % 2 === 0]; const Demo = () => { - const validator = useCallback(s => [s === '' ? null : (s * 1) % 2 === 0], []); - const [state, setState, [isValid]] = useValidatableState(validator, ''); + const [state, setState] = React.useState(0); + const [[isValid]] = useStateValidator(state, DemoStateValidator); return (
@@ -21,7 +21,7 @@ const Demo = () => { min="0" max="10" value={state} - onChange={ev => { + onChange={(ev: React.ChangeEvent) => { setState(ev.target.value); }} /> @@ -33,16 +33,15 @@ const Demo = () => { ## Reference ```ts -const [state, setState, validity, revalidate] = useValidatableState( - validator: (state, prev, setValidity?)=>[boolean|null, ...any[]], - initialState: any +const [validity, revalidate] = useStateValidator( + state: any, + validator: (state, setValidity?)=>[boolean|null, ...any[]], + initialValidity: any ); ``` -- `state` and `setState` are the same with React's `useState` hook; - **`validity`**_`: [boolean|null, ...any[]]`_ result of validity check. First element is strictly nullable boolean, but others can contain arbitrary data; - **`revalidate`**_`: ()=>void`_ runs validator once again -- **`validator`** should return an array suitable for validity state described above; +- **`validator`**_`: (state, setValidity?)=>[boolean|null, ...any[]]`_ should return an array suitable for validity state described above; - `state` - current state; - - `prev` - previous state; - `setValidity` - if defined hook will not trigger validity change automatically. Useful for async validators; -- `initialState` same with `useState` hook; +- `initialValidity` - validity value which set when validity is nt calculated yet; diff --git a/src/__stories__/useValidityState.story.tsx b/src/__stories__/useStateValidator.tsx similarity index 52% rename from src/__stories__/useValidityState.story.tsx rename to src/__stories__/useStateValidator.tsx index 66e9651e..906de0cb 100644 --- a/src/__stories__/useValidityState.story.tsx +++ b/src/__stories__/useStateValidator.tsx @@ -1,12 +1,12 @@ import { storiesOf } from '@storybook/react'; import * as React from 'react'; -import { useCallback } from 'react'; -import { useValidatableState } from '../index'; +import useStateValidator from '../useStateValidator'; import ShowDocs from './util/ShowDocs'; +const DemoStateValidator = s => [s === '' ? null : (s * 1) % 2 === 0]; const Demo = () => { - const validator = useCallback(s => [s === '' ? null : (s * 1) % 2 === 0], []); - const [state, setState, [isValid]] = useValidatableState(validator, ''); + const [state, setState] = React.useState(0); + const [[isValid]] = useStateValidator(state, DemoStateValidator); return (
@@ -16,7 +16,7 @@ const Demo = () => { min="0" max="10" value={state} - onChange={ev => { + onChange={(ev: React.ChangeEvent) => { setState(ev.target.value); }} /> @@ -25,6 +25,6 @@ const Demo = () => { ); }; -storiesOf('State|useValidatableState', module) - .add('Docs', () => ) +storiesOf('State|useStateValidator', module) + .add('Docs', () => ) .add('Demo', () => ); diff --git a/src/__tests__/useStateValidator.test.ts b/src/__tests__/useStateValidator.test.ts new file mode 100644 index 00000000..7b717541 --- /dev/null +++ b/src/__tests__/useStateValidator.test.ts @@ -0,0 +1,100 @@ +import { act, renderHook, RenderHookResult } from '@testing-library/react-hooks'; +import { useState } from 'react'; +import useStateValidator, { UseValidatorReturn, Validator } from '../useStateValidator'; + +interface Mock extends jest.Mock {} + +describe('useStateValidator', () => { + it('should be defined', () => { + expect(useStateValidator).toBeDefined(); + }); + + function getHook( + fn: Validator = jest.fn(state => [!!(state % 2)]) + ): [jest.Mock | Function, RenderHookResult]>] { + return [ + fn, + renderHook(() => { + const [state, setState] = useState(1); + + return [setState, useStateValidator(state, fn)]; + }), + ]; + } + + it('should return an array of two elements', () => { + const [, hook] = getHook(); + const res = hook.result.current[1]; + + expect(Array.isArray(res)).toBe(true); + expect(res[0]).toEqual([true]); + expect(typeof res[1]).toBe('function'); + }); + + it('first element should represent current validity state', () => { + const [, hook] = getHook(); + let [setState, [validity]] = hook.result.current; + expect(validity).toEqual([true]); + + act(() => setState(3)); + [setState, [validity]] = hook.result.current; + expect(validity).toEqual([true]); + + act(() => setState(4)); + [setState, [validity]] = hook.result.current; + expect(validity).toEqual([false]); + }); + + it('second element should re-call validation', () => { + const [spy, hook] = getHook(); + const [, [, revalidate]] = hook.result.current; + + expect(spy).toHaveBeenCalledTimes(1); + act(() => revalidate()); + expect(spy).toHaveBeenCalledTimes(2); + }); + + it('validator have to be called on init plus on each state update', () => { + const [spy, hook] = getHook(jest.fn()); + const [setState] = hook.result.current; + + expect(spy).toHaveBeenCalledTimes(1); + act(() => setState(4)); + expect(spy).toHaveBeenCalledTimes(2); + act(() => setState(prevState => prevState + 1)); + expect(spy).toHaveBeenCalledTimes(3); + }); + + it('should pass to validator one parameter - current state', () => { + const [spy, hook] = getHook(jest.fn()); + const [setState] = hook.result.current; + + act(() => setState(4)); + act(() => setState(5)); + expect((spy as Mock).mock.calls[0].length).toBe(1); + expect((spy as Mock).mock.calls[0].length).toBe(1); + expect((spy as Mock).mock.calls[0][0]).toBe(1); + expect((spy as Mock).mock.calls[1].length).toBe(1); + expect((spy as Mock).mock.calls[1][0]).toBe(4); + expect((spy as Mock).mock.calls[2].length).toBe(1); + expect((spy as Mock).mock.calls[2][0]).toBe(5); + }); + + it('if validator expects 2nd parameters it should pass a validity setter there', () => { + const [spy, hook] = getHook(jest.fn((state, setValidity) => setValidity!([state % 2 === 0]))); + let [setState, [[isValid]]] = hook.result.current; + + expect((spy as Mock).mock.calls[0].length).toBe(2); + expect(typeof (spy as Mock).mock.calls[0][1]).toBe('function'); + + expect(isValid).toBe(false); + act(() => setState(prevState => prevState + 1)); + + [setState, [[isValid]]] = hook.result.current; + expect(isValid).toBe(true); + act(() => setState(5)); + + [setState, [[isValid]]] = hook.result.current; + expect(isValid).toBe(false); + }); +}); diff --git a/src/__tests__/useValidatableState.test.ts b/src/__tests__/useValidatableState.test.ts deleted file mode 100644 index 0e0bc515..00000000 --- a/src/__tests__/useValidatableState.test.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { act, renderHook, RenderHookResult } from '@testing-library/react-hooks'; -import { useValidatableState } from '../index'; -import { UseValidatableStateReturn, Validator } from '../useValidatableState'; - -interface Mock extends jest.Mock {} - -describe('useValidatableState', () => { - it('should be defined', () => { - expect(useValidatableState).toBeDefined(); - }); - - function getHook( - fn: Validator = jest.fn(() => {}), - initialState: any = null - ): [Mock | Function, RenderHookResult<{ validator: Validator; init: any }, UseValidatableStateReturn>] { - return [ - fn, - renderHook(({ validator, init }) => useValidatableState(validator as Function, init), { - initialProps: { - validator: fn, - init: initialState, - }, - }), - ]; - } - - it('should return an array of four elements', () => { - const [, hook] = getHook(); - - expect(Array.isArray(hook.result.current)).toBe(true); - expect(hook.result.current.length).toBe(4); - }); - - it('first two elements should act like regular setState', () => { - const [, hook] = getHook(jest.fn(), 3); - const [, setState] = hook.result.current; - - expect(hook.result.current[0]).toBe(3); - act(() => setState(4)); - expect(hook.result.current[0]).toBe(4); - act(() => setState(prevState => prevState + 1)); - expect(hook.result.current[0]).toBe(5); - }); - - it('validator have to be called on init plus on each state update', () => { - const [spy, hook] = getHook(jest.fn(), 3); - const [, setState] = hook.result.current; - - expect(spy).toHaveBeenCalledTimes(1); - act(() => setState(4)); - expect(spy).toHaveBeenCalledTimes(2); - act(() => setState(prevState => prevState + 1)); - expect(spy).toHaveBeenCalledTimes(3); - }); - - it('third element of returned array should represent validity state', () => { - const [, hook] = getHook(jest.fn(state => [state % 2 === 0]), 3); - let [, setState, [isValid]] = hook.result.current; - - expect(isValid).toBe(false); - act(() => setState(prevState => prevState + 1)); - - [, setState, [isValid]] = hook.result.current; - expect(isValid).toBe(true); - act(() => setState(5)); - - [, setState, [isValid]] = hook.result.current; - expect(isValid).toBe(false); - }); - - it('should recalculate validity on validator change', () => { - const [, hook] = getHook(jest.fn(state => [state % 2 === 0]), 3); - let [, setState, [isValid]] = hook.result.current; - - expect(isValid).toBe(false); - - hook.rerender({ validator: jest.fn(state => [state % 2 === 1]), init: 3 }); - - [, setState, [isValid]] = hook.result.current; - expect(isValid).toBe(true); - act(() => setState(prevState => prevState + 1)); - - [, setState, [isValid]] = hook.result.current; - expect(isValid).toBe(false); - }); - - it('forth element of returned array should re-call validation', () => { - const [spy, hook] = getHook(jest.fn(), 3); - const [, , , validate] = hook.result.current; - - expect(spy).toHaveBeenCalledTimes(1); - act(() => validate()); - expect(spy).toHaveBeenCalledTimes(2); - }); - - it('should pass to validator two parameters: first - current state, second - previous state', () => { - const [spy, hook] = getHook(jest.fn(), 3); - const [, setState] = hook.result.current; - - act(() => setState(4)); - act(() => setState(prevState => prevState + 1)); - expect((spy as Mock).mock.calls[0][0]).toBe(3); - expect((spy as Mock).mock.calls[0][1]).toBe(null); - expect((spy as Mock).mock.calls[1][0]).toBe(4); - expect((spy as Mock).mock.calls[1][1]).toBe(3); - expect((spy as Mock).mock.calls[2][0]).toBe(5); - expect((spy as Mock).mock.calls[2][1]).toBe(4); - }); - - it('if validator expects 3 parameters it should pass a validity setter there', () => { - const [spy, hook] = getHook(jest.fn((state, _prevState, setValidity) => setValidity!([state % 2 === 0])), 3); - let [, setState, [isValid]] = hook.result.current; - - expect(typeof (spy as Mock).mock.calls[0][2]).toBe('function'); - - expect(isValid).toBe(false); - act(() => setState(prevState => prevState + 1)); - - [, setState, [isValid]] = hook.result.current; - expect(isValid).toBe(true); - act(() => setState(5)); - - [, setState, [isValid]] = hook.result.current; - expect(isValid).toBe(false); - }); -}); diff --git a/src/index.ts b/src/index.ts index 412e1bd7..a3a933fe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -86,7 +86,7 @@ export { default as useUpdate } from './useUpdate'; export { default as useUpdateEffect } from './useUpdateEffect'; export { default as useUpsert } from './useUpsert'; export { default as useVideo } from './useVideo'; -export { default as useValidatableState } from './useValidatableState'; +export { default as useStateValidator } from './useStateValidator'; export { useWait, Waiter } from './useWait'; export { default as useWindowScroll } from './useWindowScroll'; export { default as useWindowSize } from './useWindowSize'; diff --git a/src/useStateValidator.ts b/src/useStateValidator.ts new file mode 100644 index 00000000..cf9070f0 --- /dev/null +++ b/src/useStateValidator.ts @@ -0,0 +1,36 @@ +import { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react'; + +export type ValidityState = [boolean | undefined, ...any[]]; +export type DispatchValidity = Dispatch>; + +export type Validator = + | { + (state?: S): V; + (state?: S, dispatch?: DispatchValidity): void; + } + | Function; + +export type UseValidatorReturn = [V, () => void]; + +export default function useStateValidator( + state: S, + validator: Validator, + initialValidity: V = [undefined] as V +): UseValidatorReturn { + const validatorFn = useRef(validator); + + const [validity, setValidity] = useState(initialValidity); + const validate = useCallback(() => { + if (validatorFn.current.length === 2) { + validatorFn.current(state, setValidity); + } else { + setValidity(validatorFn.current(state)); + } + }, [state]); + + useEffect(() => { + validate(); + }, [state]); + + return [validity, validate]; +} diff --git a/src/useValidatableState.ts b/src/useValidatableState.ts deleted file mode 100644 index 2d0b9b46..00000000 --- a/src/useValidatableState.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react'; - -export type ValidityState = [boolean | null, ...any[]]; -export type DispatchValidityState = Dispatch>; - -export type Validator = - | { - (state?: State, prev?: State): StateValidity; - (state?: State, prev?: State, setValidity?: DispatchValidityState): void; - } - | Function; - -export type ValidateFn = () => void; - -export type UseValidatableStateReturn = [ - State, - Dispatch>, - StateValidity, - ValidateFn -]; - -export default function useValidatableState( - validator: Validator, - initialState?: State -): UseValidatableStateReturn { - const prevState = useRef(null); - const [state, setState] = useState(initialState!); - const [validity, setValidity] = useState([null] as StateValidity); - - const validate = useCallback(() => { - if (validator.length === 3) { - validator(state, prevState.current, setValidity as DispatchValidityState); - } else { - setValidity(validator(state, prevState.current)); - } - }, [state, validator]); - - useEffect(() => { - validate(); - }, [validate, state]); - useEffect(() => { - prevState.current = state; - }, [state]); - - return [state, setState, validity, validate]; -} From 1920f8b135cd64ce2fb9a534cdb4d85e779a060b Mon Sep 17 00:00:00 2001 From: xobotyi Date: Fri, 11 Oct 2019 04:26:45 +0300 Subject: [PATCH 47/62] Readme update --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c08670cc..4c554d30 100644 --- a/README.md +++ b/README.md @@ -131,9 +131,9 @@ - [`useStateList`](./docs/useStateList.md) — circularly iterates over an array. - [`useToggle` and `useBoolean`](./docs/useToggle.md) — tracks state of a boolean. - [`useCounter` and `useNumber`](./docs/useCounter.md) — tracks state of a number. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usecounter--demo) - - [`useList`](./docs/useList.md) — tracks state of an array. - - [`useMap`](./docs/useMap.md) — tracks state of an object. - - [`useValidatableState`](./docs/useValidatableState.md) — tracks state of an object. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usevalidatablestate--demo) + - [`useList`](./docs/useList.md) and [`useUpsert`](./docs/useUpsert.md) — tracks state of an array. [![][img-demo]](https://codesandbox.io/s/wonderful-mahavira-1sm0w) + - [`useMap`](./docs/useMap.md) — tracks state of an object. [![][img-demo]](https://codesandbox.io/s/quirky-dewdney-gi161) + - [`useStateValidator`](./docs/useStateValidator.md) — tracks state of an object. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usestatevalidator--demo)
From ed8e26d7c2ba2d044410e46a2421c86a7e51e928 Mon Sep 17 00:00:00 2001 From: Ward Date: Sat, 12 Oct 2019 18:27:31 +1100 Subject: [PATCH 48/62] fix: improve use of refs in dependency lists (#655) --- src/useFullscreen.ts | 2 +- src/useMouse.ts | 2 +- src/useScroll.ts | 2 +- src/useScrolling.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/useFullscreen.ts b/src/useFullscreen.ts index afb754fd..c55b0d3d 100644 --- a/src/useFullscreen.ts +++ b/src/useFullscreen.ts @@ -65,7 +65,7 @@ const useFullscreen = (ref: RefObject, on: boolean, options: FullScreen video.current.webkitExitFullscreen(); } }; - }, [ref.current, video, on]); + }, [on, video, ref]); return isFullscreen; }; diff --git a/src/useMouse.ts b/src/useMouse.ts index 7e692a8d..665a126b 100644 --- a/src/useMouse.ts +++ b/src/useMouse.ts @@ -62,7 +62,7 @@ const useMouse = (ref: RefObject): State => { cancelAnimationFrame(frame.current); document.removeEventListener('mousemove', moveHandler); }; - }, [ref.current]); + }, [ref]); return state; }; diff --git a/src/useScroll.ts b/src/useScroll.ts index a98a7c3f..caf78f49 100644 --- a/src/useScroll.ts +++ b/src/useScroll.ts @@ -48,7 +48,7 @@ const useScroll = (ref: RefObject): State => { ref.current.removeEventListener('scroll', handler); } }; - }, [ref.current]); + }, [ref]); return state; }; diff --git a/src/useScrolling.ts b/src/useScrolling.ts index 01dd1174..c95ae6c2 100644 --- a/src/useScrolling.ts +++ b/src/useScrolling.ts @@ -25,7 +25,7 @@ const useScrolling = (ref: RefObject): boolean => { }; } return () => {}; - }, [ref.current]); + }, [ref]); return scrolling; }; From c0b3c3021e0d60a7c3304f19096568793d14ed43 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sat, 12 Oct 2019 07:29:20 +0000 Subject: [PATCH 49/62] chore(release): 12.3.2 [skip ci] ## [12.3.2](https://github.com/streamich/react-use/compare/v12.3.1...v12.3.2) (2019-10-12) ### Bug Fixes * improve use of refs in dependency lists ([#655](https://github.com/streamich/react-use/issues/655)) ([ed8e26d](https://github.com/streamich/react-use/commit/ed8e26d)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17f4c954..4a347391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [12.3.2](https://github.com/streamich/react-use/compare/v12.3.1...v12.3.2) (2019-10-12) + + +### Bug Fixes + +* improve use of refs in dependency lists ([#655](https://github.com/streamich/react-use/issues/655)) ([ed8e26d](https://github.com/streamich/react-use/commit/ed8e26d)) + ## [12.3.1](https://github.com/streamich/react-use/compare/v12.3.0...v12.3.1) (2019-10-10) diff --git a/package.json b/package.json index 54797164..043fdb10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-use", - "version": "12.3.1", + "version": "12.3.2", "description": "Collection of React Hooks", "main": "lib/index.js", "module": "esm/index.js", From 8fcf8d4dd713eefbe4c5240384cc6f765120b407 Mon Sep 17 00:00:00 2001 From: Ward Oosterlijnck Date: Sat, 12 Oct 2019 18:41:54 +1100 Subject: [PATCH 50/62] docs: fix useStateValidator story --- .../{useStateValidator.tsx => useStateValidator.story.tsx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/__stories__/{useStateValidator.tsx => useStateValidator.story.tsx} (100%) diff --git a/src/__stories__/useStateValidator.tsx b/src/__stories__/useStateValidator.story.tsx similarity index 100% rename from src/__stories__/useStateValidator.tsx rename to src/__stories__/useStateValidator.story.tsx From 87d461319a55fa5e9c629fa1a9d77a9a90ec13ea Mon Sep 17 00:00:00 2001 From: Kevin Norris Date: Sat, 12 Oct 2019 21:12:51 +1300 Subject: [PATCH 51/62] tests: useLogger (#670) --- src/__tests__/useLogger.test.ts | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/__tests__/useLogger.test.ts diff --git a/src/__tests__/useLogger.test.ts b/src/__tests__/useLogger.test.ts new file mode 100644 index 00000000..85989b9f --- /dev/null +++ b/src/__tests__/useLogger.test.ts @@ -0,0 +1,41 @@ +import { renderHook } from '@testing-library/react-hooks'; +import useLogger from '../useLogger'; + +const logSpy = jest.spyOn(global.console, 'log').mockImplementation(() => {}); + +describe('useLogger', () => { + it('should be defined', () => { + expect(useLogger).toBeDefined(); + }); + + it('should log the provided props on mount', () => { + const props = { question: 'What is the meaning?', answer: 42 }; + renderHook(() => useLogger('Test', props)); + + expect(logSpy).toBeCalledTimes(1); + expect(logSpy).toHaveBeenLastCalledWith('Test mounted', props); + }); + + it('should log when the component has unmounted', () => { + const props = { question: 'What is the meaning?', answer: 42 }; + const { unmount } = renderHook(() => useLogger('Test', props)); + + unmount(); + + expect(logSpy).toHaveBeenLastCalledWith('Test unmounted'); + }); + + it('should log updates as props change', () => { + const { rerender } = renderHook( + ({ componentName, props }: { componentName: string; props: any }) => useLogger(componentName, props), + { + initialProps: { componentName: 'Test', props: { one: 1 } }, + } + ); + + const newProps = { one: 1, two: 2 }; + rerender({ componentName: 'Test', props: newProps }); + + expect(logSpy).toHaveBeenLastCalledWith('Test updated', newProps); + }); +}); From d5f359f7e3f7b913d5437518fb94b98c963d2193 Mon Sep 17 00:00:00 2001 From: Kevin Norris Date: Sat, 12 Oct 2019 21:22:23 +1300 Subject: [PATCH 52/62] feat: useIntersection (#652) React sensor hook that tracks the changes in the intersection of a target element with an ancestor element or with a top-level document's viewport, using the Intersection Observer API --- README.md | 5 +- docs/useIntersection.md | 36 +++++++ package.json | 1 + src/__stories__/useIntersection.story.tsx | 53 ++++++++++ src/__tests__/useIntersection.test.tsx | 119 ++++++++++++++++++++++ src/index.ts | 1 + src/useIntersection.ts | 30 ++++++ yarn.lock | 93 ++++++++++++++++- 8 files changed, 334 insertions(+), 4 deletions(-) create mode 100644 docs/useIntersection.md create mode 100644 src/__stories__/useIntersection.story.tsx create mode 100644 src/__tests__/useIntersection.test.tsx create mode 100644 src/useIntersection.ts diff --git a/README.md b/README.md index fcc219a6..e1af98a4 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ - [`useGeolocation`](./docs/useGeolocation.md) — tracks geo location state of user's device. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usegeolocation--demo) - [`useHover` and `useHoverDirty`](./docs/useHover.md) — tracks mouse hover state of some element. [![][img-demo]](https://codesandbox.io/s/zpn583rvx) - [`useIdle`](./docs/useIdle.md) — tracks whether user is being inactive. + - [`useIntersection`](./docs/useIntersection.md) — tracks an HTML element's intersection. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-useintersection--demo) - [`useKey`](./docs/useKey.md), [`useKeyPress`](./docs/useKeyPress.md), [`useKeyboardJs`](./docs/useKeyboardJs.md), and [`useKeyPressEvent`](./docs/useKeyPressEvent.md) — track keys. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usekeypressevent--demo) - [`useLocation`](./docs/useLocation.md) and [`useSearchParam`](./docs/useSearchParam.md) — tracks page navigation bar location state. - [`useMedia`](./docs/useMedia.md) — tracks state of a CSS media query. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usemedia--demo) @@ -104,7 +105,7 @@ - [`useTitle`](./docs/useTitle.md) — sets title of the page. - [`usePermission`](./docs/usePermission.md) — query permission status for browser APIs.
-
+
- [**Lifecycles**](./docs/Lifecycles.md) - [`useEffectOnce`](./docs/useEffectOnce.md) — a modified [`useEffect`](https://reactjs.org/docs/hooks-reference.html#useeffect) hook that only runs once. - [`useEvent`](./docs/useEvent.md) — subscribe to events. @@ -135,7 +136,6 @@ - [`useMap`](./docs/useMap.md) — tracks state of an object. [![][img-demo]](https://codesandbox.io/s/quirky-dewdney-gi161) - [`useStateValidator`](./docs/useStateValidator.md) — tracks state of an object. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usestatevalidator--demo) -


@@ -160,7 +160,6 @@ [img-demo]: https://img.shields.io/badge/demo-%20%20%20%F0%9F%9A%80-green.svg -

Contributors

diff --git a/docs/useIntersection.md b/docs/useIntersection.md new file mode 100644 index 00000000..802ee1da --- /dev/null +++ b/docs/useIntersection.md @@ -0,0 +1,36 @@ +# `useIntersection` + +React sensor hook that tracks the changes in the intersection of a target element with an ancestor element or with a top-level document's viewport. Uses the [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) and returns a [IntersectionObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry). + +## Usage + +```jsx +import * as React from 'react'; +import { useIntersection } from 'react-use'; + +const Demo = () => { + const intersectionRef = React.useRef(null); + const intersection = useIntersection(intersectionRef, { + root: null, + rootMargin: '0px', + threshold: 1 + }); + + return ( +
+ {intersection && intersection.intersectionRatio < 1 + ? 'Obscured' + : 'Fully in view'} +
+ ); +}; +``` + +## Reference + +```ts +useIntersection( + ref: RefObject, + options: IntersectionObserverInit, +): IntersectionObserverEntry | null; +``` diff --git a/package.json b/package.json index 043fdb10..e898b378 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "@semantic-release/changelog": "3.0.4", "@semantic-release/git": "7.0.16", "@semantic-release/npm": "5.1.13", + "@shopify/jest-dom-mocks": "^2.8.2", "@storybook/addon-actions": "5.1.11", "@storybook/addon-knobs": "5.1.11", "@storybook/addon-notes": "5.1.11", diff --git a/src/__stories__/useIntersection.story.tsx b/src/__stories__/useIntersection.story.tsx new file mode 100644 index 00000000..fb8c1226 --- /dev/null +++ b/src/__stories__/useIntersection.story.tsx @@ -0,0 +1,53 @@ +import { storiesOf } from '@storybook/react'; +import * as React from 'react'; +import { useIntersection } from '..'; +import ShowDocs from './util/ShowDocs'; + +const Spacer = () => ( +
+); + +const Demo = () => { + const intersectionRef = React.useRef(null); + const intersection = useIntersection(intersectionRef, { + root: null, + rootMargin: '0px', + threshold: 1, + }); + + return ( +
+ Scroll me + +
+ {intersection && intersection.intersectionRatio < 1 ? 'Obscured' : 'Fully in view'} +
+ +
+ ); +}; + +storiesOf('Sensors/useIntersection', module) + .add('Docs', () => ) + .add('Demo', () => ); diff --git a/src/__tests__/useIntersection.test.tsx b/src/__tests__/useIntersection.test.tsx new file mode 100644 index 00000000..ee7342b2 --- /dev/null +++ b/src/__tests__/useIntersection.test.tsx @@ -0,0 +1,119 @@ +import React, { createRef } from 'react'; +import ReactDOM from 'react-dom'; +import TestUtils from 'react-dom/test-utils'; +import TestRenderer from 'react-test-renderer'; +import { intersectionObserver } from '@shopify/jest-dom-mocks'; +import { renderHook } from '@testing-library/react-hooks'; +import { useIntersection } from '..'; + +beforeEach(() => { + intersectionObserver.mock(); +}); + +afterEach(() => { + intersectionObserver.restore(); +}); + +describe('useIntersection', () => { + const container = document.createElement('div'); + let targetRef; + + it('should be defined', () => { + expect(useIntersection).toBeDefined(); + }); + + it('should setup an IntersectionObserver targeting the ref element and using the options provided', () => { + TestUtils.act(() => { + targetRef = createRef(); + ReactDOM.render(
, container); + }); + + expect(intersectionObserver.observers).toHaveLength(0); + const observerOptions = { root: null, threshold: 0.8 }; + + renderHook(() => useIntersection(targetRef, observerOptions)); + + expect(intersectionObserver.observers).toHaveLength(1); + expect(intersectionObserver.observers[0].target).toEqual(targetRef.current); + expect(intersectionObserver.observers[0].options).toEqual(observerOptions); + }); + + it('should return null if a ref without a current value is provided', () => { + targetRef = createRef(); + + const { result } = renderHook(() => useIntersection(targetRef, { root: null, threshold: 1 })); + expect(result.current).toBe(null); + }); + + it('should return the first IntersectionObserverEntry when the IntersectionObserver registers an intersection', () => { + TestUtils.act(() => { + targetRef = createRef(); + ReactDOM.render(
, container); + }); + + const { result } = renderHook(() => useIntersection(targetRef, { root: container, threshold: 0.8 })); + + const mockIntersectionObserverEntry = { + boundingClientRect: targetRef.current.getBoundingClientRect(), + intersectionRatio: 0.81, + intersectionRect: container.getBoundingClientRect(), + isIntersecting: true, + rootBounds: container.getBoundingClientRect(), + target: targetRef.current, + time: 300, + }; + TestRenderer.act(() => { + intersectionObserver.simulate(mockIntersectionObserverEntry); + }); + + expect(result.current).toEqual(mockIntersectionObserverEntry); + }); + + it('should setup a new IntersectionObserver when the ref changes', () => { + let newRef; + TestUtils.act(() => { + targetRef = createRef(); + newRef = createRef(); + ReactDOM.render( +
+ +
, + container + ); + }); + + const observerOptions = { root: null, threshold: 0.8 }; + const { rerender } = renderHook(({ ref, options }) => useIntersection(ref, options), { + initialProps: { ref: targetRef, options: observerOptions }, + }); + + expect(intersectionObserver.observers[0].target).toEqual(targetRef.current); + + TestRenderer.act(() => { + rerender({ ref: newRef, options: observerOptions }); + }); + + expect(intersectionObserver.observers[0].target).toEqual(newRef.current); + }); + + it('should setup a new IntersectionObserver when the options change', () => { + TestUtils.act(() => { + targetRef = createRef(); + ReactDOM.render(
, container); + }); + + const initialObserverOptions = { root: null, threshold: 0.8 }; + const { rerender } = renderHook(({ ref, options }) => useIntersection(ref, options), { + initialProps: { ref: targetRef, options: initialObserverOptions }, + }); + + expect(intersectionObserver.observers[0].options).toEqual(initialObserverOptions); + + const newObserverOptions = { root: container, threshold: 1 }; + TestRenderer.act(() => { + rerender({ ref: targetRef, options: newObserverOptions }); + }); + + expect(intersectionObserver.observers[0].options).toEqual(newObserverOptions); + }); +}); diff --git a/src/index.ts b/src/index.ts index a3a933fe..65872134 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,6 +27,7 @@ export { default as useHarmonicIntervalFn } from './useHarmonicIntervalFn'; export { default as useHover } from './useHover'; export { default as useHoverDirty } from './useHoverDirty'; export { default as useIdle } from './useIdle'; +export { default as useIntersection } from './useIntersection'; export { default as useInterval } from './useInterval'; export { default as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'; export { default as useKey } from './useKey'; diff --git a/src/useIntersection.ts b/src/useIntersection.ts new file mode 100644 index 00000000..4a7b78ea --- /dev/null +++ b/src/useIntersection.ts @@ -0,0 +1,30 @@ +import { RefObject, useEffect, useState } from 'react'; + +const useIntersection = ( + ref: RefObject, + options: IntersectionObserverInit +): IntersectionObserverEntry | null => { + const [intersectionObserverEntry, setIntersectionObserverEntry] = useState(null); + + useEffect(() => { + if (ref.current) { + const handler = (entries: IntersectionObserverEntry[]) => { + setIntersectionObserverEntry(entries[0]); + }; + + const observer = new IntersectionObserver(handler, options); + observer.observe(ref.current); + + return () => { + if (ref.current) { + observer.disconnect(); + } + }; + } + return () => {}; + }, [ref, options.threshold, options.root, options.rootMargin]); + + return intersectionObserverEntry; +}; + +export default useIntersection; diff --git a/yarn.lock b/yarn.lock index 60fc2e3b..051f3791 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1712,6 +1712,37 @@ into-stream "^4.0.0" lodash "^4.17.4" +"@shopify/async@^2.0.7": + version "2.0.7" + resolved "https://registry.yarnpkg.com/@shopify/async/-/async-2.0.7.tgz#944992bc1721df6c363b3f0f31be1dad0e75e929" + integrity sha512-wYGjqPhpna4ShYbUmlD2fPv5ZkjNlCZtU7huUU8/snnyPmdgL/Rn5M5FPP6Apr7/hU5RgqMj2tJFs37ORz/VaQ== + +"@shopify/decorators@^1.1.5": + version "1.1.5" + resolved "https://registry.yarnpkg.com/@shopify/decorators/-/decorators-1.1.5.tgz#b8da0bd5fffb04cde9730898fc04428f964cab1c" + integrity sha512-cFAwd7T5IjkPs1ef11dbA6cbJA+CtgCDanbalPlQdl5ItwDzqJXGpvbhbQXw7zPyNMLijrgrpQqltalqAy9wnQ== + dependencies: + "@shopify/function-enhancers" "^1.0.5" + +"@shopify/function-enhancers@^1.0.5": + version "1.0.5" + resolved "https://registry.yarnpkg.com/@shopify/function-enhancers/-/function-enhancers-1.0.5.tgz#7c3e516e26ce7a9b63c263679bdcf5121d994a10" + integrity sha512-34ML8DX4RmmA9hXDlf2BAz4SA37unShZxoBRPz585a+FaEzNcMvw5NzLD+Ih9XrP/wrxTUcN+p6pazvoS+jB7w== + +"@shopify/jest-dom-mocks@^2.8.2": + version "2.8.2" + resolved "https://registry.yarnpkg.com/@shopify/jest-dom-mocks/-/jest-dom-mocks-2.8.2.tgz#477c3159897807cc8d7797c33e8a79e787051779" + integrity sha512-4drt+S1cQ1ZSP1DaEHAj5XPPCiI2R8IIt+ZnH9h08Ngy8PjtjFFNHNcSJ6bKBmk7eO2c6+5UaJQzNcg56nt7gg== + dependencies: + "@shopify/async" "^2.0.7" + "@shopify/decorators" "^1.1.5" + "@types/fetch-mock" "^6.0.1" + "@types/lolex" "^2.1.3" + fetch-mock "^6.3.0" + lolex "^2.7.5" + promise "^8.0.3" + tslib "^1.9.3" + "@storybook/addon-actions@5.1.11": version "5.1.11" resolved "https://registry.yarnpkg.com/@storybook/addon-actions/-/addon-actions-5.1.11.tgz#ebc299b9dfe476b5c65eb5d148c4b064f682ca08" @@ -2219,6 +2250,11 @@ resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g== +"@types/fetch-mock@^6.0.1": + version "6.0.5" + resolved "https://registry.yarnpkg.com/@types/fetch-mock/-/fetch-mock-6.0.5.tgz#acbc6771d43d7ebc1f0a8b7e3d57147618f8eacb" + integrity sha512-rV8O2j/TIi0PtFCOlK55JnfKpE8Hm6PKFgrUZY/3FNHw4uBEMHnM+5ZickDO1duOyKxbpY3VES5T4NIwZXvodA== + "@types/glob@^7.1.1": version "7.1.1" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" @@ -2260,6 +2296,11 @@ dependencies: "@types/jest-diff" "*" +"@types/lolex@^2.1.3": + version "2.1.3" + resolved "https://registry.yarnpkg.com/@types/lolex/-/lolex-2.1.3.tgz#793557c9b8ad319b4c8e4c6548b90893f4aa5f69" + integrity sha512-nEipOLYyZJ4RKHCg7tlR37ewFy91oggmip2MBzPdVQ8QhTFqjcRhE8R0t4tfpDnSlxGWHoEGJl0UCC4kYhqoiw== + "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -2857,7 +2898,7 @@ arrify@^1.0.1: resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d" integrity sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0= -asap@^2.0.0, asap@~2.0.3: +asap@^2.0.0, asap@~2.0.3, asap@~2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46" integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY= @@ -3317,6 +3358,15 @@ babel-plugin-transform-undefined-to-void@^6.9.4: resolved "https://registry.yarnpkg.com/babel-plugin-transform-undefined-to-void/-/babel-plugin-transform-undefined-to-void-6.9.4.tgz#be241ca81404030678b748717322b89d0c8fe280" integrity sha1-viQcqBQEAwZ4t0hxcyK4nQyP4oA= +babel-polyfill@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153" + integrity sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM= + dependencies: + babel-runtime "^6.26.0" + core-js "^2.5.0" + regenerator-runtime "^0.10.5" + babel-preset-jest@^24.9.0: version "24.9.0" resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-24.9.0.tgz#192b521e2217fb1d1f67cf73f70c336650ad3cdc" @@ -5644,6 +5694,15 @@ fbjs@^0.8.0, fbjs@^0.8.1: setimmediate "^1.0.5" ua-parser-js "^0.7.18" +fetch-mock@^6.3.0: + version "6.5.2" + resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-6.5.2.tgz#b3842b305c13ea0f81c85919cfaa7de387adfa3e" + integrity sha512-EIvbpCLBTYyDLu4HJiqD7wC8psDwTUaPaWXNKZbhNO/peUYKiNp5PkZGKRJtnTxaPQu71ivqafvjpM7aL+MofQ== + dependencies: + babel-polyfill "^6.26.0" + glob-to-regexp "^0.4.0" + path-to-regexp "^2.2.1" + figgy-pudding@^3.4.1, figgy-pudding@^3.5.1: version "3.5.1" resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.1.tgz#862470112901c727a0e495a80744bd5baa1d6790" @@ -6145,6 +6204,11 @@ glob-to-regexp@^0.3.0: resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab" integrity sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs= +glob-to-regexp@^0.4.0: + version "0.4.1" + resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e" + integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw== + glob@^7.0.0, glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4: version "7.1.4" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255" @@ -8300,6 +8364,11 @@ log-update@^2.3.0: cli-cursor "^2.0.0" wrap-ansi "^3.0.1" +lolex@^2.7.5: + version "2.7.5" + resolved "https://registry.yarnpkg.com/lolex/-/lolex-2.7.5.tgz#113001d56bfc7e02d56e36291cc5c413d1aa0733" + integrity sha512-l9x0+1offnKKIzYVjyXU2SiwhXDLekRzKyhnbyldPHvC7BvLPVpdNUNR2KeMAiCN2D/kLNttZgQD5WjSxuBx3Q== + loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" @@ -9776,6 +9845,11 @@ path-to-regexp@0.1.7: resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w= +path-to-regexp@^2.2.1: + version "2.4.0" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-2.4.0.tgz#35ce7f333d5616f1c1e1bfe266c3aba2e5b2e704" + integrity sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w== + path-type@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f" @@ -10096,6 +10170,13 @@ promise@^7.1.1: dependencies: asap "~2.0.3" +promise@^8.0.3: + version "8.0.3" + resolved "https://registry.yarnpkg.com/promise/-/promise-8.0.3.tgz#f592e099c6cddc000d538ee7283bb190452b0bf6" + integrity sha512-HeRDUL1RJiLhyA0/grn+PTShlBAcLuh/1BJGtrvjwbvRDCTLLMEz9rOGCV+R3vHY4MixIuoMEd9Yq/XvsTPcjw== + dependencies: + asap "~2.0.6" + prompts@^2.0.1: version "2.0.4" resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.0.4.tgz#179f9d4db3128b9933aa35f93a800d8fce76a682" @@ -10892,6 +10973,11 @@ regenerate@^1.4.0: resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg== +regenerator-runtime@^0.10.5: + version "0.10.5" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658" + integrity sha1-M2w+/BIgrc7dosn6tntaeVWjNlg= + regenerator-runtime@^0.11.0: version "0.11.1" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" @@ -12506,6 +12592,11 @@ tslib@1.9.0, tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8" integrity sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ== +tslib@^1.9.3: + version "1.10.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" + integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== + tslint-config-prettier@1.18.0: version "1.18.0" resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.18.0.tgz#75f140bde947d35d8f0d238e0ebf809d64592c37" From 38dffea37cd515b96ede208e5ae5a9d658179605 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sat, 12 Oct 2019 08:24:03 +0000 Subject: [PATCH 53/62] chore(release): 12.4.0 [skip ci] # [12.4.0](https://github.com/streamich/react-use/compare/v12.3.2...v12.4.0) (2019-10-12) ### Features * useIntersection ([#652](https://github.com/streamich/react-use/issues/652)) ([d5f359f](https://github.com/streamich/react-use/commit/d5f359f)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a347391..793f4b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [12.4.0](https://github.com/streamich/react-use/compare/v12.3.2...v12.4.0) (2019-10-12) + + +### Features + +* useIntersection ([#652](https://github.com/streamich/react-use/issues/652)) ([d5f359f](https://github.com/streamich/react-use/commit/d5f359f)) + ## [12.3.2](https://github.com/streamich/react-use/compare/v12.3.1...v12.3.2) (2019-10-12) diff --git a/package.json b/package.json index e898b378..036ee217 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-use", - "version": "12.3.2", + "version": "12.4.0", "description": "Collection of React Hooks", "main": "lib/index.js", "module": "esm/index.js", From fb5a925feaf77272fa09915cac2000c7110b1429 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 12 Oct 2019 20:03:46 +1100 Subject: [PATCH 54/62] chore(deps): pin dependency @shopify/jest-dom-mocks to 2.8.2 (#671) --- package.json | 2 +- yarn.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 036ee217..45263456 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@semantic-release/changelog": "3.0.4", "@semantic-release/git": "7.0.16", "@semantic-release/npm": "5.1.13", - "@shopify/jest-dom-mocks": "^2.8.2", + "@shopify/jest-dom-mocks": "2.8.2", "@storybook/addon-actions": "5.1.11", "@storybook/addon-knobs": "5.1.11", "@storybook/addon-notes": "5.1.11", diff --git a/yarn.lock b/yarn.lock index 051f3791..16dfbda6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1729,7 +1729,7 @@ resolved "https://registry.yarnpkg.com/@shopify/function-enhancers/-/function-enhancers-1.0.5.tgz#7c3e516e26ce7a9b63c263679bdcf5121d994a10" integrity sha512-34ML8DX4RmmA9hXDlf2BAz4SA37unShZxoBRPz585a+FaEzNcMvw5NzLD+Ih9XrP/wrxTUcN+p6pazvoS+jB7w== -"@shopify/jest-dom-mocks@^2.8.2": +"@shopify/jest-dom-mocks@2.8.2": version "2.8.2" resolved "https://registry.yarnpkg.com/@shopify/jest-dom-mocks/-/jest-dom-mocks-2.8.2.tgz#477c3159897807cc8d7797c33e8a79e787051779" integrity sha512-4drt+S1cQ1ZSP1DaEHAj5XPPCiI2R8IIt+ZnH9h08Ngy8PjtjFFNHNcSJ6bKBmk7eO2c6+5UaJQzNcg56nt7gg== From 282f04b6f6c6752dcdbb689df4cf27587dfd9f29 Mon Sep 17 00:00:00 2001 From: Ward Oosterlijnck Date: Sat, 12 Oct 2019 21:03:35 +1100 Subject: [PATCH 55/62] docs: useMeasure and useSize docs tidy --- README.md | 4 ++-- docs/useMeasure.md | 12 +++++++++--- docs/useSize.md | 6 +++++- src/__stories__/useMeasure.story.tsx | 12 +++--------- src/__stories__/useSize.story.tsx | 7 +++---- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e1af98a4..ebe6c734 100644 --- a/README.md +++ b/README.md @@ -61,11 +61,11 @@ - [`usePageLeave`](./docs/usePageLeave.md) — triggers when mouse leaves page boundaries. - [`useScroll`](./docs/useScroll.md) — tracks an HTML element's scroll position. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usescroll--docs) - [`useScrolling`](./docs/useScrolling.md) — tracks whether HTML element is scrolling. - - [`useSize`](./docs/useSize.md) — tracks an HTML element's dimensions. + - [`useSize`](./docs/useSize.md) — tracks an HTML element's size. - [`useStartTyping`](./docs/useStartTyping.md) — detects when user starts typing. - [`useWindowScroll`](./docs/useWindowScroll.md) — tracks `Window` scroll position. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usewindowscroll--docs) - [`useWindowSize`](./docs/useWindowSize.md) — tracks `Window` dimensions. [![][img-demo]](https://codesandbox.io/s/m7ln22668) - - [`useMeasure`](./docs/useMeasure.md) — tracks an HTML element's dimensions by [Resize Observer](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver).[![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usemeasure--demo) + - [`useMeasure`](./docs/useMeasure.md) — tracks an HTML element's dimensions using the Resize Observer API.[![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usemeasure--demo)

- [**UI**](./docs/UI.md) diff --git a/docs/useMeasure.md b/docs/useMeasure.md index 92b5db7b..0f574fbc 100644 --- a/docs/useMeasure.md +++ b/docs/useMeasure.md @@ -1,6 +1,6 @@ # `useMeasure` -React sensor hook that reacts to changes in size of any of the observed elements. +React sensor hook that tracks dimensions of an HTML element using the [Resize Observer API](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver). ## Usage @@ -8,12 +8,18 @@ React sensor hook that reacts to changes in size of any of the observed elements import { useMeasure } from "react-use"; const Demo = () => { - const [ref, { width, height }] = useMeasure(); + const [ref, { x, y, width, height, top, right, bottom, left }] = useMeasure(); return (
+
x: {x}
+
y: {y}
width: {width}
height: {height}
+
top: {top}
+
right: {right}
+
bottom: {bottom}
+
left: {left}
); }; @@ -21,4 +27,4 @@ const Demo = () => { ## Related hooks -- [useSize](./useSize.md) \ No newline at end of file +- [useSize](./useSize.md) diff --git a/docs/useSize.md b/docs/useSize.md index 3e8868f5..3784d017 100644 --- a/docs/useSize.md +++ b/docs/useSize.md @@ -9,7 +9,7 @@ import {useSize} from 'react-use'; const Demo = () => { const [sized, {width, height}] = useSize( - ({width}) =>
Size me up! ({width}px)
, + ({width}) =>
Size me up! ({width}px)
, { width: 100, height: 100 } ); @@ -31,3 +31,7 @@ useSize(element, initialSize); - `element` — sized element. - `initialSize` — initial size containing a `width` and `height` key. + +## Related hooks + +- [useMeasure](./useMeasure.md) diff --git a/src/__stories__/useMeasure.story.tsx b/src/__stories__/useMeasure.story.tsx index c91fa18b..2431f993 100644 --- a/src/__stories__/useMeasure.story.tsx +++ b/src/__stories__/useMeasure.story.tsx @@ -4,18 +4,12 @@ import { useMeasure } from '..'; import ShowDocs from './util/ShowDocs'; const Demo = () => { - const [ref, { width, height }] = useMeasure(); + const [ref, state] = useMeasure(); return ( <> -
width: {width}
-
height: {height}
-
+
{JSON.stringify(state, null, 2)}
+
resize me
diff --git a/src/__stories__/useSize.story.tsx b/src/__stories__/useSize.story.tsx index c029359a..9310b377 100644 --- a/src/__stories__/useSize.story.tsx +++ b/src/__stories__/useSize.story.tsx @@ -4,15 +4,14 @@ import { useSize } from '..'; import ShowDocs from './util/ShowDocs'; const Demo = () => { - const [sized, { width, height }] = useSize(({ width: currentWidth }) => ( -
Size me up! ({currentWidth}px)
+ const [sized, state] = useSize(({ width: currentWidth }) => ( +
Size me up! ({currentWidth}px)
)); return (
+
{JSON.stringify(state, null, 2)}
{sized} -
width: {width}
-
height: {height}
); }; From 6afa6b4793e4011aa7809897d9fea9aedbae8562 Mon Sep 17 00:00:00 2001 From: Jose Felix Date: Sat, 12 Oct 2019 20:13:43 -0400 Subject: [PATCH 56/62] tests: useDeepCompareEffect and useUpdateEffect tests (#663) --- src/__tests__/useDeepCompareEffect.test.ts | 39 ++++++++++++++++++++++ src/__tests__/useUpdateEffect.test.ts | 13 ++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/__tests__/useDeepCompareEffect.test.ts create mode 100644 src/__tests__/useUpdateEffect.test.ts diff --git a/src/__tests__/useDeepCompareEffect.test.ts b/src/__tests__/useDeepCompareEffect.test.ts new file mode 100644 index 00000000..965495de --- /dev/null +++ b/src/__tests__/useDeepCompareEffect.test.ts @@ -0,0 +1,39 @@ +import { renderHook } from '@testing-library/react-hooks'; +import { useDeepCompareEffect } from '..'; +import { useEffect } from 'react'; + +let options = { max: 10 }; +const mockEffectNormal = jest.fn(); +const mockEffectDeep = jest.fn(); +const mockEffectCleanup = jest.fn(); +const mockEffectCallback = jest.fn().mockReturnValue(mockEffectCleanup); + +it('should run provided object once', () => { + const { rerender: rerenderNormal } = renderHook(() => useEffect(mockEffectNormal, [options])); + const { rerender: rerenderDeep } = renderHook(() => useDeepCompareEffect(mockEffectDeep, [options])); + + expect(mockEffectNormal).toHaveBeenCalledTimes(1); + expect(mockEffectDeep).toHaveBeenCalledTimes(1); + + options = { max: 10 }; + rerenderDeep(); + rerenderNormal(); + + expect(mockEffectNormal).toHaveBeenCalledTimes(2); + expect(mockEffectDeep).toHaveBeenCalledTimes(1); + + options = { max: 10 }; + rerenderNormal(); + rerenderDeep(); + + expect(mockEffectNormal).toHaveBeenCalledTimes(3); + expect(mockEffectDeep).toHaveBeenCalledTimes(1); +}); + +it('should run clean-up provided on unmount', () => { + const { unmount } = renderHook(() => useDeepCompareEffect(mockEffectCallback, [options])); + expect(mockEffectCleanup).not.toHaveBeenCalled(); + + unmount(); + expect(mockEffectCleanup).toHaveBeenCalledTimes(1); +}); diff --git a/src/__tests__/useUpdateEffect.test.ts b/src/__tests__/useUpdateEffect.test.ts new file mode 100644 index 00000000..933395d4 --- /dev/null +++ b/src/__tests__/useUpdateEffect.test.ts @@ -0,0 +1,13 @@ +import { renderHook } from '@testing-library/react-hooks'; +import { useUpdateEffect } from '..'; + +const mockEffectCleanup = jest.fn(); +const mockEffectCallback = jest.fn().mockReturnValue(mockEffectCleanup); + +it('should run effect on update', () => { + const { rerender } = renderHook(() => useUpdateEffect(mockEffectCallback)); + expect(mockEffectCallback).not.toHaveBeenCalled(); + + rerender(); + expect(mockEffectCallback).toHaveBeenCalledTimes(1); +}); From 2310f54091397e4a31fc707e0220a75395db59b9 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sat, 12 Oct 2019 23:56:01 +0000 Subject: [PATCH 57/62] chore(deps): update dependency husky to v3.0.9 --- package.json | 2 +- yarn.lock | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 45263456..f6397918 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "babel-plugin-dynamic-import-node": "2.3.0", "fork-ts-checker-webpack-plugin": "1.5.0", "gh-pages": "2.1.1", - "husky": "3.0.8", + "husky": "3.0.9", "jest": "24.9.0", "keyboardjs": "2.5.1", "lint-staged": "9.4.2", diff --git a/yarn.lock b/yarn.lock index 16dfbda6..f7a974f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6647,20 +6647,20 @@ humanize-url@^1.0.0: normalize-url "^1.0.0" strip-url-auth "^1.0.0" -husky@3.0.8: - version "3.0.8" - resolved "https://registry.yarnpkg.com/husky/-/husky-3.0.8.tgz#8de3fed26ce9b43034ef51013c4ad368b6b74ea8" - integrity sha512-HFOsgcyrX3qe/rBuqyTt+P4Gxn5P0seJmr215LAZ/vnwK3jWB3r0ck7swbzGRUbufCf9w/lgHPVbF/YXQALgfQ== +husky@3.0.9: + version "3.0.9" + resolved "https://registry.yarnpkg.com/husky/-/husky-3.0.9.tgz#a2c3e9829bfd6b4957509a9500d2eef5dbfc8044" + integrity sha512-Yolhupm7le2/MqC1VYLk/cNmYxsSsqKkTyBhzQHhPK1jFnC89mmmNVuGtLNabjDI6Aj8UNIr0KpRNuBkiC4+sg== dependencies: chalk "^2.4.2" + ci-info "^2.0.0" cosmiconfig "^5.2.1" execa "^1.0.0" get-stdin "^7.0.0" - is-ci "^2.0.0" opencollective-postinstall "^2.0.2" pkg-dir "^4.2.0" please-upgrade-node "^3.2.0" - read-pkg "^5.1.1" + read-pkg "^5.2.0" run-node "^1.0.0" slash "^3.0.0" @@ -9785,6 +9785,16 @@ parse-json@^4.0.0: error-ex "^1.3.1" json-parse-better-errors "^1.0.1" +parse-json@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-5.0.0.tgz#73e5114c986d143efa3712d4ea24db9a4266f60f" + integrity sha512-OOY5b7PAEFV0E2Fir1KOkxchnZNCdowAJgQ5NuxjpBKTRP3pQhwkrkxqQjeoKJ+fO7bCpmIZaogI4eZGDMEGOw== + dependencies: + "@babel/code-frame" "^7.0.0" + error-ex "^1.3.1" + json-parse-better-errors "^1.0.1" + lines-and-columns "^1.1.6" + parse5@4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/parse5/-/parse5-4.0.0.tgz#6d78656e3da8d78b4ec0b906f7c08ef1dfe3f608" @@ -10802,6 +10812,16 @@ read-pkg@^5.0.0, read-pkg@^5.1.1: parse-json "^4.0.0" type-fest "^0.4.1" +read-pkg@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-5.2.0.tgz#7bf295438ca5a33e56cd30e053b34ee7250c93cc" + integrity sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg== + dependencies: + "@types/normalize-package-data" "^2.4.0" + normalize-package-data "^2.5.0" + parse-json "^5.0.0" + type-fest "^0.6.0" + read@1, read@~1.0.1, read@~1.0.7: version "1.0.7" resolved "https://registry.yarnpkg.com/read/-/read-1.0.7.tgz#b3da19bd052431a97671d44a42634adf710b40c4" @@ -12699,6 +12719,11 @@ type-fest@^0.5.0: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.5.2.tgz#d6ef42a0356c6cd45f49485c3b6281fc148e48a2" integrity sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw== +type-fest@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.6.0.tgz#8d2a2370d3df886eb5c90ada1c5bf6188acf838b" + integrity sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg== + type-is@~1.6.17, type-is@~1.6.18: version "1.6.18" resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" From a38f026beb193ac31a728bd06095337eaa6afe95 Mon Sep 17 00:00:00 2001 From: Ward Date: Sun, 13 Oct 2019 17:54:30 +1100 Subject: [PATCH 58/62] refactor: useInterval refactor + docs (#626) --- docs/useInterval.md | 23 +++++++++++------------ src/__stories__/useInterval.story.tsx | 20 ++++++++++---------- src/useInterval.ts | 7 ++++--- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/useInterval.md b/docs/useInterval.md index 03679acf..5c3ae9a7 100644 --- a/docs/useInterval.md +++ b/docs/useInterval.md @@ -1,6 +1,6 @@ # `useInterval` -React hook that allow you using declarative `setInterval`. +A declarative interval hook based on [Dan Abramov's article on overreacted.io](https://overreacted.io/making-setinterval-declarative-with-react-hooks). The interval can be paused by setting the delay to `null`. ## Usage @@ -11,32 +11,31 @@ import {useInterval} from 'react-use'; const Demo = () => { const [count, setCount] = React.useState(0); const [delay, setDelay] = React.useState(1000); + const [isRunning, toggleIsRunning] = useBoolean(true); - useInterval(() => { - setCount(count + 1); - }, delay); - - function handleDelayChange(e) { - setDelay(Number(e.target.value)); - } + useInterval( + () => { + setCount(count + 1); + }, + isRunning ? delay : null + ); return (
- delay: + delay: setDelay(Number(event.target.value))} />

count: {count}

- +
); }; ``` - ## Reference ```js -useInterval(fn, delay?: number) +useInterval(callback, delay?: number) ``` diff --git a/src/__stories__/useInterval.story.tsx b/src/__stories__/useInterval.story.tsx index 7ac3d37c..2e460308 100644 --- a/src/__stories__/useInterval.story.tsx +++ b/src/__stories__/useInterval.story.tsx @@ -1,28 +1,28 @@ import { storiesOf } from '@storybook/react'; import * as React from 'react'; -import { useInterval } from '..'; +import { useInterval, useBoolean } from '..'; import ShowDocs from './util/ShowDocs'; const Demo = () => { const [count, setCount] = React.useState(0); const [delay, setDelay] = React.useState(1000); + const [isRunning, toggleIsRunning] = useBoolean(true); - useInterval(() => { - setCount(count + 1); - }, delay); - - function handleDelayChange(e) { - setDelay(Number(e.target.value)); - } + useInterval( + () => { + setCount(count + 1); + }, + isRunning ? delay : null + ); return (
- delay: + delay: setDelay(Number(event.target.value))} />

count: {count}

- +
); diff --git a/src/useInterval.ts b/src/useInterval.ts index f411cc74..4613d5e9 100644 --- a/src/useInterval.ts +++ b/src/useInterval.ts @@ -1,17 +1,18 @@ import { useEffect, useRef } from 'react'; const useInterval = (callback: Function, delay?: number | null) => { - const latestCallback = useRef(() => {}); + const savedCallback = useRef(() => {}); useEffect(() => { - latestCallback.current = callback; + savedCallback.current = callback; }); useEffect(() => { if (delay !== null) { - const interval = setInterval(() => latestCallback.current(), delay || 0); + const interval = setInterval(() => savedCallback.current(), delay || 0); return () => clearInterval(interval); } + return undefined; }, [delay]); }; From a624364d8bee2a65ef9094dfa2413811b5602bf4 Mon Sep 17 00:00:00 2001 From: Ward Date: Mon, 14 Oct 2019 07:38:04 +1100 Subject: [PATCH 59/62] feat: useList allow pushing multiple items (#621) --- src/__tests__/useList.test.ts | 13 +++++++++++++ src/useList.ts | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/__tests__/useList.test.ts b/src/__tests__/useList.test.ts index f8dc9584..47b5beb7 100644 --- a/src/__tests__/useList.test.ts +++ b/src/__tests__/useList.test.ts @@ -104,6 +104,19 @@ it('should push duplicated element at the end of the list', () => { expect(result.current[0]).not.toBe(initList); // checking immutability }); +it('should push multiple elements at the end of the list', () => { + const initList = [1, 2, 3]; + const { result } = setUp(initList); + const [, utils] = result.current; + + act(() => { + utils.push(4, 5, 6); + }); + + expect(result.current[0]).toEqual([1, 2, 3, 4, 5, 6]); + expect(result.current[0]).not.toBe(initList); // checking immutability +}); + it('should filter current list by provided function', () => { const initList = [1, -1, 2, -2, 3, -3]; const { result } = setUp(initList); diff --git a/src/useList.ts b/src/useList.ts index 50000818..eecdc507 100644 --- a/src/useList.ts +++ b/src/useList.ts @@ -5,7 +5,7 @@ export interface Actions { clear: () => void; updateAt: (index: number, item: T) => void; remove: (index: number) => void; - push: (item: T) => void; + push: (...items: T[]) => void; filter: (fn: (value: T) => boolean) => void; sort: (fn?: (a: T, b: T) => number) => void; reset: () => void; @@ -21,7 +21,7 @@ const useList = (initialList: T[] = []): [T[], Actions] => { updateAt: (index, entry) => set(currentList => [...currentList.slice(0, index), entry, ...currentList.slice(index + 1)]), remove: index => set(currentList => [...currentList.slice(0, index), ...currentList.slice(index + 1)]), - push: entry => set(currentList => [...currentList, entry]), + push: (...entry) => set(currentList => [...currentList, ...entry]), filter: fn => set(currentList => currentList.filter(fn)), sort: (fn?) => set(currentList => [...currentList].sort(fn)), reset: () => set([...initialList]), From 7955c3e1e058562317c3e79c4fbc8a5187648f52 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sun, 13 Oct 2019 20:40:24 +0000 Subject: [PATCH 60/62] chore(release): 12.5.0 [skip ci] # [12.5.0](https://github.com/streamich/react-use/compare/v12.4.0...v12.5.0) (2019-10-13) ### Features * useList allow pushing multiple items ([#621](https://github.com/streamich/react-use/issues/621)) ([a624364](https://github.com/streamich/react-use/commit/a624364)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 793f4b92..61180767 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [12.5.0](https://github.com/streamich/react-use/compare/v12.4.0...v12.5.0) (2019-10-13) + + +### Features + +* useList allow pushing multiple items ([#621](https://github.com/streamich/react-use/issues/621)) ([a624364](https://github.com/streamich/react-use/commit/a624364)) + # [12.4.0](https://github.com/streamich/react-use/compare/v12.3.2...v12.4.0) (2019-10-12) diff --git a/package.json b/package.json index f6397918..9b3401ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-use", - "version": "12.4.0", + "version": "12.5.0", "description": "Collection of React Hooks", "main": "lib/index.js", "module": "esm/index.js", From 5bf8f8e9ee00a9ca0273d3f6c570424e6bc42a88 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sun, 13 Oct 2019 22:08:37 +0000 Subject: [PATCH 61/62] chore(deps): update node.js to v12.11.1 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4f2c037c..b56cb858 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 refs: container: &container docker: - - image: node:12.9.1 + - image: node:12.11.1 working_directory: ~/repo steps: - &Versions From 7dd7ba87add498a63dbf1cb8ad1373b7f94f256a Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 14 Oct 2019 09:26:44 +0000 Subject: [PATCH 62/62] chore(deps): update dependency fork-ts-checker-webpack-plugin to v1.5.1 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9b3401ce..cd2cf5e9 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "babel-core": "6.26.3", "babel-loader": "8.0.6", "babel-plugin-dynamic-import-node": "2.3.0", - "fork-ts-checker-webpack-plugin": "1.5.0", + "fork-ts-checker-webpack-plugin": "1.5.1", "gh-pages": "2.1.1", "husky": "3.0.9", "jest": "24.9.0", diff --git a/yarn.lock b/yarn.lock index f7a974f2..e132f584 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5910,10 +5910,10 @@ fork-ts-checker-webpack-plugin@1.1.1: tapable "^1.0.0" worker-rpc "^0.1.0" -fork-ts-checker-webpack-plugin@1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-1.5.0.tgz#ce1d77190b44d81a761b10b6284a373795e41f0c" - integrity sha512-zEhg7Hz+KhZlBhILYpXy+Beu96gwvkROWJiTXOCyOOMMrdBIRPvsBpBqgTI4jfJGrJXcqGwJR8zsBGDmzY0jsA== +fork-ts-checker-webpack-plugin@1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-1.5.1.tgz#f82d078ba8911c7b2c70703ffb3cbe588b33fbaa" + integrity sha512-IbVh1Z46dmCXJMg6We8s9jYwCAzzSv2Tgj+G2Sg/8pFantHDBrAg/rQyPnmAWLS/djW7n4VEltoEglbtTvt0wQ== dependencies: babel-code-frame "^6.22.0" chalk "^2.4.1"