@react-hook/window-scroll
Advanced tools
Comparing version 1.2.3 to 1.3.0
@@ -1,35 +0,24 @@ | ||
'use strict' | ||
"use strict"; | ||
exports.__esModule = true | ||
exports.default = exports.useWindowScroll = void 0 | ||
exports.__esModule = true; | ||
exports.default = exports.useWindowScroll = void 0; | ||
var _throttle = require('@react-hook/throttle') | ||
var _throttle = /*#__PURE__*/require("@react-hook/throttle"); | ||
var _event = _interopRequireDefault(require('@react-hook/event')) | ||
var _event = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("@react-hook/event")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj} | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const getScrollY = () => | ||
window.scrollY !== void 0 | ||
? window.scrollY | ||
: window.pageYOffset === void 0 | ||
? 0 | ||
: window.pageYOffset | ||
const win = typeof window === 'undefined' ? null : window; | ||
const win = typeof window === 'undefined' ? null : window | ||
const getScrollY = () => win.scrollY !== void 0 ? win.scrollY : win.pageYOffset === void 0 ? 0 : win.pageYOffset; | ||
const useWindowScroll = (fps = 30) => { | ||
const [scrollY, setThrottledScroll] = (0, _throttle.useThrottle)( | ||
typeof window === 'undefined' ? 0 : getScrollY, | ||
fps, | ||
true | ||
) | ||
;(0, _event.default)(win, 'scroll', () => setThrottledScroll(getScrollY())) | ||
return scrollY | ||
} | ||
const state = (0, _throttle.useThrottle)(typeof window === 'undefined' ? 0 : getScrollY, fps, true); | ||
(0, _event.default)(win, 'scroll', () => state[1](getScrollY())); | ||
return state[0]; | ||
}; | ||
exports.useWindowScroll = useWindowScroll | ||
var _default = useWindowScroll | ||
exports.default = _default | ||
exports.useWindowScroll = useWindowScroll; | ||
var _default = useWindowScroll; | ||
exports.default = _default; |
@@ -1,21 +0,12 @@ | ||
import {useThrottle} from '@react-hook/throttle' | ||
import useEvent from '@react-hook/event' | ||
import { useThrottle } from '@react-hook/throttle'; | ||
import useEvent from '@react-hook/event'; | ||
const win = typeof window === 'undefined' ? null : window; | ||
const getScrollY = () => | ||
window.scrollY !== void 0 | ||
? window.scrollY | ||
: window.pageYOffset === void 0 | ||
? 0 | ||
: window.pageYOffset | ||
const getScrollY = () => win.scrollY !== void 0 ? win.scrollY : win.pageYOffset === void 0 ? 0 : win.pageYOffset; | ||
const win = typeof window === 'undefined' ? null : window | ||
export const useWindowScroll = (fps = 30) => { | ||
const [scrollY, setThrottledScroll] = useThrottle( | ||
typeof window === 'undefined' ? 0 : getScrollY, | ||
fps, | ||
true | ||
) | ||
useEvent(win, 'scroll', () => setThrottledScroll(getScrollY())) | ||
return scrollY | ||
} | ||
export default useWindowScroll | ||
const state = useThrottle(typeof window === 'undefined' ? 0 : getScrollY, fps, true); | ||
useEvent(win, 'scroll', () => state[1](getScrollY())); | ||
return state[0]; | ||
}; | ||
export default useWindowScroll; |
106
package.json
{ | ||
"name": "@react-hook/window-scroll", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"homepage": "https://github.com/jaredLunde/react-hook/tree/master/packages/window-scroll#readme", | ||
@@ -32,59 +32,111 @@ "repository": "github:jaredLunde/react-hook", | ||
"module": "dist/module/index.js", | ||
"unpkg": "dist/umd/use-scroll-position.js", | ||
"source": "src/index.tsx", | ||
"types": "types/index.d.ts", | ||
"files": [ | ||
"/dist", | ||
"/src", | ||
"/types" | ||
], | ||
"exports": { | ||
".": { | ||
"browser": "./dist/module/index.js", | ||
"import": "./dist/esm/index.mjs", | ||
"require": "./dist/main/index.js", | ||
"umd": "./dist/umd/use-scroll-position.js", | ||
"source": "./src/index.tsx", | ||
"types": "./types/index.d.ts", | ||
"default": "./dist/main/index.js" | ||
}, | ||
"./package.json": "./package.json", | ||
"./": "./" | ||
}, | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "npm run build-main && npm run build-module && npm run build-types", | ||
"build-main": "npm run compile -- -d dist/main --env-name main", | ||
"build-module": "npm run compile -- -d dist/module --env-name module", | ||
"build-types": "tsc -p tsconfig.json -d --outDir types --emitDeclarationOnly", | ||
"check-types": "tsc --noEmit -p tsconfig.json", | ||
"compile": "babel src -x .ts,.tsx --ignore \"**/*.test.ts\",\"**/test.ts\",\"**/*.test.tsx\",\"**/test.tsx\" --delete-dir-on-start", | ||
"format": "prettier --write \"**/*.{ts,js,md,yml,json,babelrc,eslintrc,prettierrc}\"", | ||
"lint": "eslint . --ext .ts", | ||
"build": "lundle build --umd-case camel", | ||
"check-types": "lundle check-types", | ||
"dev": "lundle build -f module,cjs -w", | ||
"format": "prettier --write \"{,!(node_modules|dist|coverage)/**/}*.{ts,tsx,js,jsx,md,yml,json}\"", | ||
"lint": "eslint . --ext .ts,.tsx", | ||
"prepublishOnly": "npm run lint && npm run test && npm run build && npm run format", | ||
"test": "jest", | ||
"validate": "npm run check-types && npm run lint && npm run test -- --coverage" | ||
"validate": "lundle check-types && npm run lint && jest --coverage" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "npm run build-types && prettier --write \"types/**/*.d.ts\" && lint-staged" | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"**/*.{ts,js}": [ | ||
"**/*.{ts,tsx,js,jsx}": [ | ||
"lundle build -f types", | ||
"eslint", | ||
"prettier --write" | ||
], | ||
"**/*.{md,yml,json,eslintrc,prettierrc}": [ | ||
"**/*.{md,yml,json}": [ | ||
"prettier --write" | ||
] | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"lunde" | ||
] | ||
}, | ||
"eslintIgnore": [ | ||
"node_modules", | ||
"coverage", | ||
"dist", | ||
"test", | ||
"*.config.js" | ||
], | ||
"jest": { | ||
"moduleDirectories": [ | ||
"node_modules", | ||
"src", | ||
"test" | ||
], | ||
"testMatch": [ | ||
"<rootDir>/src/**/?(*.)test.{ts,tsx}" | ||
], | ||
"collectCoverageFrom": [ | ||
"**/src/**/*.{ts,tsx}" | ||
], | ||
"setupFilesAfterEnv": [ | ||
"./test/setup.js" | ||
], | ||
"snapshotResolver": "./test/resolve-snapshot.js", | ||
"globals": { | ||
"__DEV__": true | ||
} | ||
}, | ||
"prettier": { | ||
"semi": false, | ||
"singleQuote": true, | ||
"jsxSingleQuote": true, | ||
"bracketSpacing": false | ||
}, | ||
"devDependencies": { | ||
"@lunde/babel-preset-es": "latest", | ||
"@testing-library/react-hooks": "^3.2.1", | ||
"@testing-library/jest-dom": "latest", | ||
"@testing-library/react": "latest", | ||
"@testing-library/react-hooks": "latest", | ||
"@testing-library/user-event": "latest", | ||
"@types/jest": "latest", | ||
"@typescript-eslint/eslint-plugin": "latest", | ||
"@typescript-eslint/parser": "latest", | ||
"babel-plugin-optimize-react": "^0.0.4", | ||
"cross-env": "latest", | ||
"@types/react": "latest", | ||
"@types/react-dom": "latest", | ||
"babel-jest": "latest", | ||
"eslint": "latest", | ||
"eslint-import-resolver-jest": "latest", | ||
"eslint-plugin-jest": "latest", | ||
"eslint-config-lunde": "latest", | ||
"husky": "latest", | ||
"jest": "latest", | ||
"lint-staged": "latest", | ||
"lundle": "latest", | ||
"prettier": "latest", | ||
"react": "^16.12.0", | ||
"react-test-renderer": "^16.12.0", | ||
"rimraf": "^2.6.3", | ||
"ts-jest": "latest", | ||
"react": "latest", | ||
"react-dom": "latest", | ||
"react-test-renderer": "latest", | ||
"typescript": "latest" | ||
}, | ||
"dependencies": { | ||
"@react-hook/event": "^1.1.0", | ||
"@react-hook/throttle": "^2.1.2" | ||
"@react-hook/event": "^1.2.1", | ||
"@react-hook/throttle": "^2.2.0" | ||
}, | ||
@@ -91,0 +143,0 @@ "peerDependencies": { |
@@ -37,3 +37,3 @@ <hr> | ||
const Component = props => { | ||
const Component = (props) => { | ||
const scrollY = useScrollPosition(60 /*fps*/) | ||
@@ -40,0 +40,0 @@ return <div>scroll pos: {scrollY}</div> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22287
12
133
1
1
Updated@react-hook/event@^1.2.1
Updated@react-hook/throttle@^2.2.0