diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 6d906dc475..0000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,148 +0,0 @@ -version: 2 - -refs: - container: &container - docker: - - image: node:12.19.0 - working_directory: ~/repo - steps: - - &Versions - run: - name: Versions - command: node -v && npm -v && yarn -v - - &CacheRestore - restore_cache: - key: dependency-cache-{{ checksum "yarn.lock" }} - - &Install - run: - name: Install Dependencies - command: yarn install --pure-lockfile - - &CacheSave - save_cache: - key: dependency-cache-{{ checksum "yarn.lock" }} - paths: - - ./node_modules - - &Build - run: - name: Build - command: yarn build - - &Build_Storybook - run: - name: Build Storybook - command: yarn storybook:build - - &Lint - run: - name: Lint - command: yarn lint - - &Test - run: - name: Test - command: yarn test - - &Upload_Storybook - run: - name: Upload Storybook - command: yarn storybook:upload - - &Release - run: - name: Release - command: yarn release - - &Commit_Status_Storybook - run: - name: Post commit status for Storybook - command: | - npx cross-ci :run curl -H "'Authorization: token \${GITHUB_TOKEN}' -H 'Accept: application/vnd.github.v3+json'" \ - "'https://api.github.com/repos/\${PROJECT_OWNER}/\${PROJECT_NAME}/statuses/$CIRCLE_SHA1'" -X POST \ - -d "'{\"state\": \"success\", \"context\": \"Storybook\", \"description\": \"\${BUILD_VERSION}\", \"target_url\": \"https://$CIRCLE_BUILD_NUM-154950925-gh.circle-artifacts.com/0/root/repo/storybook-static/index.html\"}'" - -jobs: - all: - <<: *container - steps: - - checkout - - *Versions - - *CacheRestore - - *Install - - *CacheSave - - *Build - - *Build_Storybook - - *Test - - *Lint - - store_artifacts: - path: ~/repo/storybook-static - - *Commit_Status_Storybook - - next: - <<: *container - steps: - - checkout - - *Versions - - *CacheRestore - - *Install - - *CacheSave - - *Build - - *Build_Storybook - - *Test - - *Lint - - store_artifacts: - path: ~/repo/storybook-static - - *Commit_Status_Storybook - - run: - name: Setup GitHub - command: | - git config --global user.email "streamich@gmail.com" - git config --global user.name "streamich" - git remote rm origin - git remote add origin https://${GITHUB_TOKEN}@github.com/streamich/react-use - - *Release - - master: - <<: *container - steps: - - checkout - - *Versions - - *CacheRestore - - *Install - - *CacheSave - - *Build - - *Build_Storybook - - *Test - - *Lint - - store_artifacts: - path: ~/repo/storybook-static - - *Commit_Status_Storybook - - run: - name: Setup GitHub - command: | - git config --global user.email "streamich@gmail.com" - git config --global user.name "streamich" - git remote rm origin - git remote add origin https://${GITHUB_TOKEN}@github.com/streamich/react-use - - *Upload_Storybook - - *Release - -workflows: - version: 2 - all: - jobs: - - all: - context: common-env-vars - filters: - branches: - ignore: - - master - - next - - gh-pages - next: - jobs: - - next: - context: common-env-vars - filters: - branches: - only: next - master: - jobs: - - master: - context: common-env-vars - filters: - branches: - only: master diff --git a/.editorconfig b/.editorconfig index 15f1c6f82e..92b7b4bec2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,7 +8,7 @@ indent_size = 2 indent_style = space insert_final_newline = true trim_trailing_whitespace = true -max_line_length = 120 +max_line_length = 100 [*.{ts, tsx}] ij_typescript_enforce_trailing_comma = keep @@ -24,8 +24,8 @@ ij_typescript_catch_on_new_line = false ij_typescript_spaces_within_interpolation_expressions = false [*.md] -max_line_length = 0 +max_line_length = 100 trim_trailing_whitespace = false [COMMIT_EDITMSG] -max_line_length = 0 +max_line_length = 80 diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000000..58d020238b --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,22 @@ +module.exports = { + extends: ['react-app', 'prettier'], + plugins: ['prettier'], + rules: { + 'prettier/prettier': [ + 'error', + { + singleQuote: true, + trailingComma: 'es5', + tabWidth: 2, + printWidth: 100, + semicolons: true, + quoteProps: 'as-needed', + jsxSingleQuote: false, + bracketSpacing: true, + jsxBracketSameLine: true, + arrowParens: 'always', + endOfLine: 'lf', + }, + ], + }, +}; diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 4bed466c11..0000000000 --- a/.eslintrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "react-app" -} \ No newline at end of file diff --git a/.github/workflows/check-codebase.yml b/.github/workflows/check-codebase.yml new file mode 100644 index 0000000000..be17d2e23d --- /dev/null +++ b/.github/workflows/check-codebase.yml @@ -0,0 +1,90 @@ +name: Check codebase + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: 20 + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run build + run: yarn build + + # storybook: + # name: Storybook + # runs-on: ubuntu-latest + # steps: + # - name: Check out repository + # uses: actions/checkout@v2 + + # - name: Setup node + # uses: actions/setup-node@v1 + # with: + # node-version: 20 + + # - name: Install dependencies + # run: yarn install --frozen-lockfile + + # - name: Run build:storybook + # run: yarn storybook:build + + lint: + name: Linting + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: 20 + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Lint with ESLint + run: yarn lint + + - name: Lint with TSC + if: ${{ always() }} + run: yarn lint:types + + unit-tests: + name: Unit tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, ubuntu-latest] + node: [20, 22] + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run unit tests + run: yarn test diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml new file mode 100644 index 0000000000..f732451311 --- /dev/null +++ b/.github/workflows/mirror.yml @@ -0,0 +1,21 @@ +name: Node.js CI + +on: + push: + branches: [master] + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Push To Gitlab + env: + token: ${{ secrets.GITLAB_TOKEN }} + run: | + git config user.name "streamich" + git config user.email "react-use+streamich@users.noreply.github.com" + git remote add mirror "https://oauth2:${token}@gitlab.com/streamich/react-use.git" + git push mirror master diff --git a/.github/workflows/pull_request_ci.yml b/.github/workflows/pull_request_ci.yml deleted file mode 100644 index 3d7b602b42..0000000000 --- a/.github/workflows/pull_request_ci.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Node CI - -on: [pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [10.x, 12.x] - - steps: - - uses: actions/checkout@v1 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: npm install, build, and test - run: | - yarn install --pure-lockfile - yarn build - yarn test - env: - CI: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..81ed2cc471 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Node.js CI + +on: + push: + branches: [master, next] + +jobs: + release: + if: ${{ github.event_name == 'push' && (github.event.ref == 'refs/heads/master' || github.event.ref == 'refs/heads/next') }} + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [22.x] + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: yarn + - run: yarn install --frozen-lockfile + - run: yarn lint + - run: yarn test + - run: yarn lint:types + - run: yarn build + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index b854f157bd..0000000000 --- a/.prettierrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "trailingComma": "es5", - "singleQuote": true, - "printWidth": 120, - "tabWidth": 2 -} diff --git a/CHANGELOG.md b/CHANGELOG.md index 253b6c319c..5d3c9a753e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,324 +1,233 @@ -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-15) +## [17.6.1](https://github.com/streamich/react-use/compare/v17.6.0...v17.6.1) (2026-06-10) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* **deps:** update dependency js-cookie to v3 ([c0349d9](https://github.com/streamich/react-use/commit/c0349d93be68db192f72293f8d9d0bbaf01d9829)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-15) +# [17.6.0](https://github.com/streamich/react-use/compare/v17.5.1...v17.6.0) (2024-12-09) -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-14) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-14) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-13) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-12) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-12) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-12) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-11) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-11) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-10) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-09) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-09) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-08) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-06) - - -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-05) - - -### Bug Fixes +### Features -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* add onChange callback to useWindowSize ([ea656f7](https://github.com/streamich/react-use/commit/ea656f7e751b8366360ce2aa8238057bbbc1251a)) +* add onChange callback to useWindowSize ([3eb531a](https://github.com/streamich/react-use/commit/3eb531ac9e9e04641df29aafbd2677869cdcb085)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-05) +## [17.5.1](https://github.com/streamich/react-use/compare/v17.5.0...v17.5.1) (2024-07-20) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* 🐛 bump nano-css dependency ([adfb337](https://github.com/streamich/react-use/commit/adfb337d5b11427798afc5a21c6ebdaa76212182)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-05) +# [17.5.0](https://github.com/streamich/react-use/compare/v17.4.4...v17.5.0) (2024-01-22) -### Bug Fixes +### Features -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* add `isFirst` and `isLast` methods to `useStateList` hook ([ac64414](https://github.com/streamich/react-use/commit/ac64414bea4c8afadfb382da9fea44ee89b41e2d)) +* **pencil:** add isFirst and isLast return value to 'useStateList' ([75218e4](https://github.com/streamich/react-use/commit/75218e45dfdcdc6ea193e278cb97ceee98c00f1b)) +* **pencil:** fix with yarn lint:fix ([6a9dde5](https://github.com/streamich/react-use/commit/6a9dde596ae25c0dd2fa97b0cf354143fbc5b5ff)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-05) +## [17.4.4](https://github.com/streamich/react-use/compare/v17.4.3...v17.4.4) (2024-01-21) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* typo in example ([0534648](https://github.com/streamich/react-use/commit/05346481a15a321b13838eead0bda3024b0d163f)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-03) +## [17.4.3](https://github.com/streamich/react-use/compare/v17.4.2...v17.4.3) (2024-01-13) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* update useMedia hook to use recommended approach of MDN ([e7379f0](https://github.com/streamich/react-use/commit/e7379f088787cbf9274c1fc21d36061f04855e4c)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-03) +## [17.4.2](https://github.com/streamich/react-use/compare/v17.4.1...v17.4.2) (2023-12-01) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* correct peer dependencies ([d770587](https://github.com/streamich/react-use/commit/d77058729654397b68b251e8211bf0edc0b4ed50)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-03) +## [17.4.1](https://github.com/streamich/react-use/compare/v17.4.0...v17.4.1) (2023-11-28) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* 🐛 bump nano-css version ([812952b](https://github.com/streamich/react-use/commit/812952bb9ff004a844ec4285ad6c65d39597b11c)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-10-02) +# [17.4.0](https://github.com/streamich/react-use/compare/v17.3.3...v17.4.0) (2022-05-20) -### Bug Fixes +### Features -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* add usePinchZoom sensor hook ([3e042cb](https://github.com/streamich/react-use/commit/3e042cb2f3022349a53199b5cc5c380e3ebd9975)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-29) +## [17.3.3](https://github.com/streamich/react-use/compare/v17.3.2...v17.3.3) (2022-05-20) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* bump React peer dependency version ([532e865](https://github.com/streamich/react-use/commit/532e8653a50d39dd439d9664d4813a1d7a5b4f3c)) +* resolve [#2319](https://github.com/streamich/react-use/issues/2319) ([4884b2c](https://github.com/streamich/react-use/commit/4884b2c74085e0841af7c36cca34e16d698d1b4c)) +* resolve @types/react@18 break change, React.FC ([20b7817](https://github.com/streamich/react-use/commit/20b78178d0033cc2e0c2a904e413b20ee864c816)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-28) +## [17.3.2](https://github.com/streamich/react-use/compare/v17.3.1...v17.3.2) (2021-12-30) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* useMedia SSR hydration bug with defaultState ([#2216](https://github.com/streamich/react-use/issues/2216)) ([5c01189](https://github.com/streamich/react-use/commit/5c0118941280bb265ca7813afb987f89c8c97a17)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-28) +## [17.3.1](https://github.com/streamich/react-use/compare/v17.3.0...v17.3.1) (2021-08-31) -### Bug Fixes +### Performance Improvements -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* ⚡️ change title only if it changed ([51ef8d9](https://github.com/streamich/react-use/commit/51ef8d99bad31186ec5420d8b729748507c8a1bf)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-28) +# [17.3.0](https://github.com/streamich/react-use/compare/v17.2.4...v17.3.0) (2021-08-31) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-28) +* do not re-render unncessarily in useAsyncFn hook ([fa3ba25](https://github.com/streamich/react-use/commit/fa3ba2520ede6866b599f6df55fdfa6395058cd2)) -### Bug Fixes +### Features -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* useAudio add playing state ([3203610](https://github.com/streamich/react-use/commit/3203610efdcb8e1fe3c6a17ea19e41bacbeb851b)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-28) +## [17.2.4](https://github.com/streamich/react-use/compare/v17.2.3...v17.2.4) (2021-04-23) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* lint issues. ([66b0f23](https://github.com/streamich/react-use/commit/66b0f235477c5f93807df75a53a84b3c5cd053e5)) +* **useLocalStorage:** reinitialize on key change ([fdd1b23](https://github.com/streamich/react-use/commit/fdd1b23fd7ba6ae30139eeef02c552a8c7d6d333)) +* add generic typing to createHTMLMediaHook. no typecheck problem with ref anymore. ([1f547ef](https://github.com/streamich/react-use/commit/1f547efb12d6cbe7687e86925ad80bd85fac3dfd)) +* add generic typing to createHTMLMediaHook. no typecheck problem with ref anymore. ([ac4dd78](https://github.com/streamich/react-use/commit/ac4dd786f42a2c59bdaaf9ddebe2e830982d7fcc)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-28) +## [17.2.3](https://github.com/streamich/react-use/compare/v17.2.2...v17.2.3) (2021-04-06) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* lint issues. ([5a5a575](https://github.com/streamich/react-use/commit/5a5a5755bc1f10add9c7a100ea6577ab6d427c0c)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-26) +## [17.2.2](https://github.com/streamich/react-use/compare/v17.2.1...v17.2.2) (2021-04-06) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* **useStateWithHistory:** support callback style setState ([fca687d](https://github.com/streamich/react-use/commit/fca687d32c37148dab3072f053109f6c4d3c36ba)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-26) +## [17.2.1](https://github.com/streamich/react-use/compare/v17.2.0...v17.2.1) (2021-03-11) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* lint issues. ([3e8af15](https://github.com/streamich/react-use/commit/3e8af15086135c873d18079a0b92b21da668a2ff)) +* useMeasure type definitions for SVG ([e200f7f](https://github.com/streamich/react-use/commit/e200f7fcbb371a1d794be8d350f9559f940e5760)) +* useUnmountPromise stops on immediate update ([9ff5c09](https://github.com/streamich/react-use/commit/9ff5c09e671c4f07f25f30a60617fca7660e7607)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-26) +# [17.2.0](https://github.com/streamich/react-use/compare/v17.1.1...v17.2.0) (2021-03-10) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-25) +* delete isClient ([72f4cb9](https://github.com/streamich/react-use/commit/72f4cb9b405b3729975bca3acb06658ca467d15b)) +* lint issues. ([dc5bbe0](https://github.com/streamich/react-use/commit/dc5bbe0e94d131dda90942ba90c14b200df3f34e)) +* **useOrientation:** handle orientation being 0 ([793b053](https://github.com/streamich/react-use/commit/793b0539f0305e2512e7022c45a5c33b842d24d5)) +* **useOrientation:** update tests to increase coverage ([f9c743f](https://github.com/streamich/react-use/commit/f9c743fa8375ef726d33f85285d4a5af608f9a42)) +* use window inside useEffect ([2f33aa8](https://github.com/streamich/react-use/commit/2f33aa8182c92bf56d49ec3184e6b20f0c0c1e1e)) -### Bug Fixes +### Features -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* **useOrientation:** add tests ([f45cb70](https://github.com/streamich/react-use/commit/f45cb707b52363f1cb1b32a0ebf2fdbdae79b322)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-24) +## [17.1.1](https://github.com/streamich/react-use/compare/v17.1.0...v17.1.1) (2021-02-10) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* useMountedState should not change state on componentDidUpdate lifecycle ([701b306](https://github.com/streamich/react-use/commit/701b306ed97382cbec73c834f6d3dd7baa58e339)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-23) +# [17.1.0](https://github.com/streamich/react-use/compare/v17.0.2...v17.1.0) (2021-02-01) -### Bug Fixes +### Features -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* **prettier:** make prettier a part of eslint. ([b6993a6](https://github.com/streamich/react-use/commit/b6993a6f95a1b493945c03aecc44dafd10870816)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-23) +## [17.0.2](https://github.com/streamich/react-use/compare/v17.0.1...v17.0.2) (2021-02-01) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* proper definition for `useMeasure` ([1461527](https://github.com/streamich/react-use/commit/1461527ffc55b2a1e3c9dc6a0efc2572b66e5381)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-23) +## [17.0.1](https://github.com/streamich/react-use/compare/v17.0.0...v17.0.1) (2021-01-31) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* proper definition for isBrowser and isNavigator states. ([a087deb](https://github.com/streamich/react-use/commit/a087deb48e57b1f0a23a2d0a28d0c2d10a640cd6)), closes [#1777](https://github.com/streamich/react-use/issues/1777) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-21) +# [17.0.0](https://github.com/streamich/react-use/compare/v16.1.0...v17.0.0) (2021-01-31) -### Bug Fixes - -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) - -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-20) +### Features +* refactor the useNetwork hook. ([23037f2](https://github.com/streamich/react-use/commit/23037f207d07604dd2cd7e2cc4ba9475221be780)) -### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +### BREAKING CHANGES -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-19) +* `useNetwork` hook renamed to `useNetworkState`. +# [16.1.0](https://github.com/streamich/react-use/compare/v16.0.0...v16.1.0) (2021-01-31) -### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +### Features -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-17) +* improve `on` and `off` util functions typing. ([723c588](https://github.com/streamich/react-use/commit/723c588fef6aba9f10ea9f5ea7bc444532519f9a)) +# [16.0.0](https://github.com/streamich/react-use/compare/v15.3.8...v16.0.0) (2021-01-30) -### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +### chore -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-16) +* refactoring and rearrangement. ([a27f09f](https://github.com/streamich/react-use/commit/a27f09fd367f8b172866b5fcbaf66f9a5a3481bb)) -### Bug Fixes +### BREAKING CHANGES -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* all `create*` factories been moved to `factory` subdirectory and in case direct import should be imported like `react-use/esm/factory/createBreakpoint` +* `comps` directory renamed to `component` -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-15) +## [15.3.8](https://github.com/streamich/react-use/compare/v15.3.7...v15.3.8) (2021-01-08) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* improve useStateValidator and useMultiStateValidator typings. ([acff81d](https://github.com/streamich/react-use/commit/acff81d99abdbbefcc2985297ee01c3cda9ef4c9)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-07) +## [15.3.7](https://github.com/streamich/react-use/compare/v15.3.6...v15.3.7) (2021-01-08) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* [#1646](https://github.com/streamich/react-use/issues/1646) ([ebc7094](https://github.com/streamich/react-use/commit/ebc7094bbc156be57b3de855c6984c1d056cf0e6)) -## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-06) +## [15.3.6](https://github.com/streamich/react-use/compare/v15.3.5...v15.3.6) (2021-01-07) ### Bug Fixes -* useLongPress hook linting fixes. ([9f3cc3d](https://github.com/streamich/react-use/commit/9f3cc3d33ac96b1b6f981d407ac08068af55f488)) +* Fix issues in tests ([7668ce5](https://github.com/streamich/react-use/commit/7668ce5c5f0f186437907f1c352d3a62e3ae8ba7)) ## [15.3.4](https://github.com/streamich/react-use/compare/v15.3.3...v15.3.4) (2020-09-04) diff --git a/README.md b/README.md index bbe79b978c..cc1728fafd 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ - [`useMediaDevices`](./docs/useMediaDevices.md) — tracks state of connected hardware devices. - [`useMotion`](./docs/useMotion.md) — tracks state of device's motion sensor. - [`useMouse` and `useMouseHovered`](./docs/useMouse.md) — tracks state of mouse position. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usemouse--docs) - - [`useMouseWheel`](./docs/useMouse.md) — tracks deltaY of scrolled mouse wheel. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usemousewheel--docs) - - [`useNetwork`](./docs/useNetwork.md) — tracks state of user's internet connection. + - [`useMouseWheel`](./docs/useMouseWheel.md) — tracks deltaY of scrolled mouse wheel. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usemousewheel--docs) + - [`useNetworkState`](./docs/useNetworkState.md) — tracks the state of browser's network connection. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usenetworkstate--demo) - [`useOrientation`](./docs/useOrientation.md) — tracks state of device's screen orientation. - [`usePageLeave`](./docs/usePageLeave.md) — triggers when mouse leaves page boundaries. - [`useScratch`](./docs/useScratch.md) — tracks mouse click-and-scrub state. @@ -70,6 +70,7 @@ - [`useMeasure`](./docs/useMeasure.md) and [`useSize`](./docs/useSize.md) — tracks an HTML element's dimensions. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usemeasure--demo) - [`createBreakpoint`](./docs/createBreakpoint.md) — tracks `innerWidth` - [`useScrollbarWidth`](./docs/useScrollbarWidth.md) — detects browser's native scrollbars width. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usescrollbarwidth--demo) + - [`usePinchZoom`](./docs/usePinchZoom.md) — tracks pointer events to detect pinch zoom in and out status. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usePinchZoom--demo)

- [**UI**](./docs/UI.md) @@ -121,8 +122,8 @@ - [`useMount`](./docs/useMount.md) — calls `mount` callbacks. - [`useUnmount`](./docs/useUnmount.md) — calls `unmount` callbacks. - [`useUpdateEffect`](./docs/useUpdateEffect.md) — run an `effect` only on updates. - - [`useIsomorphicLayoutEffect`](./docs/useIsomorphicLayoutEffect.md) — `useLayoutEffect` that does not show warning when server-side rendering. - - [`useDeepCompareEffect`](./docs/useDeepCompareEffect.md), [`useShallowCompareEffect`](./docs/useShallowCompareEffect.md), and [`useCustomCompareEffect`](./docs/useCustomCompareEffect.md) — run an `effect` depending on deep comparison of its dependencies + - [`useIsomorphicLayoutEffect`](./docs/useIsomorphicLayoutEffect.md) — `useLayoutEffect` that that works on server. + - [`useDeepCompareEffect`](./docs/useDeepCompareEffect.md), [`useShallowCompareEffect`](./docs/useShallowCompareEffect.md), and [`useCustomCompareEffect`](./docs/useCustomCompareEffect.md)

- [**State**](./docs/State.md) diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000000..a5497b62af --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,13 @@ +# Security Policy + +## Supported Versions + +We release patches for security vulnerabilities. The latest major version +will support security patches. + +## Reporting a Vulnerability + +Please report (suspected) security vulnerabilities to +**[streamich@gmail.com](mailto:streamich@gmail.com)**. We will try to respond +within 48 hours. If the issue is confirmed, we will release a patch as soon +as possible depending on complexity. diff --git a/docs/Usage.md b/docs/Usage.md index 90da532b99..243e354f88 100644 --- a/docs/Usage.md +++ b/docs/Usage.md @@ -16,10 +16,19 @@ Depending on your bundler you might run into a missing dependency error with ES6 ```json [ - "import", { - "libraryName": "react-use", - "libraryDirectory": "lib", - "camel2DashComponentName": false - } -] + 'import', + { + libraryName: 'react-use', + camel2DashComponentName: false, + customName(/** @type {string} */ name) { + const libraryDirectory = name.startsWith('Use') + ? 'lib/component' + : name.startsWith('create') + ? 'lib/factory' + : 'lib' + return `react-use/${libraryDirectory}/${name}` + } + }, + 'import-react-use' + ] ``` diff --git a/docs/createGlobalState.md b/docs/createGlobalState.md index b74517653a..0e02813498 100644 --- a/docs/createGlobalState.md +++ b/docs/createGlobalState.md @@ -1,6 +1,6 @@ # `useGlobalState` -A React hook which creates a globally shared state. +A React hook that creates a globally shared state. ## Usage @@ -30,3 +30,32 @@ const Demo: FC = () => { ); }; ``` + +It also allows initializing the state with a function and using a function in the setState: + +```tsx +const useGlobalValue = createGlobalState(() => 0); + +const CompA: FC = () => { + const [value, setValue] = useGlobalValue(); + + return ; +}; + +const CompB: FC = () => { + const [value, setValue] = useGlobalValue(); + + return ; +}; + +const Demo: FC = () => { + const [value] = useGlobalValue(); + return ( +
+

{value}

+ + +
+ ); +}; +``` diff --git a/docs/useAsyncFn.md b/docs/useAsyncFn.md index 94cc243ece..bf86788d92 100644 --- a/docs/useAsyncFn.md +++ b/docs/useAsyncFn.md @@ -9,7 +9,7 @@ function that returns a promise. The state is of the same shape as `useAsync`. import {useAsyncFn} from 'react-use'; const Demo = ({url}) => { - const [state, fetch] = useAsyncFn(async () => { + const [state, doFetch] = useAsyncFn(async () => { const response = await fetch(url); const result = await response.text(); return result @@ -23,7 +23,7 @@ const Demo = ({url}) => { ?
Error: {state.error.message}
:
Value: {state.value}
} - + ); }; diff --git a/docs/useAudio.md b/docs/useAudio.md index 84184037e5..8939060400 100644 --- a/docs/useAudio.md +++ b/docs/useAudio.md @@ -64,10 +64,13 @@ render tree, for example: "duration": 425.952625, "paused": false, "muted": false, - "volume": 1 + "volume": 1, + "playing": true } ``` +`playing`: The audio is being played and is affected by the network. If it starts to buffer audio, it will be false + `controls` is a list collection of methods that allow you to control the playback of the audio, it has the following interface: @@ -85,4 +88,4 @@ interface AudioControls { `ref` is a React reference to HTML `