Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "useDimensions - a React Hook to measure DOM nodes",
"main": "lib/index.js",
"module": "es/index.js",
"typings": "src/index",
"files": [
"es",
"lib",
Expand All @@ -24,9 +25,11 @@
"typescript": "^3.5.2"
},
"devDependencies": {
"@types/react": "^16.8.20",
"nwb": "0.21.x",
"react": "^16.8.4",
"react-dom": "^16.8.4"
"react-dom": "^16.8.4",
"typescript": "^3.5.2"
},
"author": "Swizec Teller",
"homepage": "https://swizec.com",
Expand Down
3 changes: 3 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { UseDimensionsArgs, UseDimensionsHook } from "./types";
declare function useDimensions({ liveMeasure }?: UseDimensionsArgs): UseDimensionsHook;
export default useDimensions;
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function useDimensions({
liveMeasure = true
}: UseDimensionsArgs = {}): UseDimensionsHook {
const [dimensions, setDimensions] = useState({});
const [node, setNode] = useState(null);
const [node, setNode] = useState<HTMLElement | null>(null);

const ref = useCallback(node => {
setNode(node);
Expand All @@ -44,9 +44,10 @@ function useDimensions({
};
}
}
return () => {}
}, [node]);

return [ref, dimensions, node];
return [ref, dimensions as DimensionObject, node];
}

export default useDimensions;
6 changes: 3 additions & 3 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export interface DimensionObject {
}

export type UseDimensionsHook = [
(node: HTMLElement) => void,
{} | DimensionObject,
HTMLElement
(node: HTMLElement | null) => void,
DimensionObject,
HTMLElement | null
];

export interface UseDimensionsArgs {
Expand Down
12 changes: 6 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
"target": "es2015",
"lib": ["es5", "es6", "es7", "es2017", "dom"],
"sourceMap": true,
"allowJs": false, // todo: make this false when all .js files have been converted to .ts/.tsx
"allowJs": false,
"jsx": "react",
"moduleResolution": "node",
"rootDirs": ["src"],
"forceConsistentCasingInFileNames": true,
// "noImplicitReturns": true, // todo: enable this when all .js files have been converted to .ts/.tsx
// "noImplicitThis": true, // todo: enable this when all .js files have been converted to .ts/.tsx
// "noImplicitAny": true, // todo: enable this when all .js files have been converted to .ts/.tsx
// "strictNullChecks": true, // todo: enable this when all .js files have been converted to .ts/.tsx
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"declaration": false, // todo: make this true when all .js files have been converted to .ts/.tsx
"declaration": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"esModuleInterop": true
Expand Down
17 changes: 11 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
integrity sha512-CFzn9idOEpHrgdw8JsoTkaDDyRWk1jrzIV8djzcgpq0y9tG4B4lFT+Nxh52DVpDXV+n4+NPNv7M1Dj5uMp6XFg==

"@types/react@^16.8.20":
version "16.8.20"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.8.20.tgz#4f633ecbd0a4d56d0ccc50fff6f9321bbcd7d583"
integrity sha512-ZLmI+ubSJpfUIlQuULDDrdyuFQORBuGOvNnMue8HeA0GVrAJbWtZQhcBvnBPNRBI/GrfSfrKPFhthzC2SLEtLQ==
version "16.9.2"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.2.tgz#6d1765431a1ad1877979013906731aae373de268"
integrity sha512-jYP2LWwlh+FTqGd9v7ynUKZzjj98T8x7Yclz479QdRhHfuW9yQ+0jjnD31eXSXutmBpppj5PYNLYLRfnZJvcfg==
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"
Expand Down Expand Up @@ -2553,9 +2553,9 @@ csso@~2.3.1:
source-map "^0.5.3"

csstype@^2.2.0:
version "2.6.5"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.5.tgz#1cd1dff742ebf4d7c991470ae71e12bb6751e034"
integrity sha512-JsTaiksRsel5n7XwqPAfB0l3TFKdpjW/kgAELf9vrb5adGA7UCPLajKK5s3nFrcFm3Rkyp/Qkgl73ENc1UY3cA==
version "2.6.6"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.6.tgz#c34f8226a94bbb10c32cc0d714afdf942291fc41"
integrity sha512-RpFbQGUE74iyPgvr46U9t1xoQBM8T4BL8SxrN66Le2xYAPSaDJJKeztV3awugusb3g3G9iL8StmkBBXhcbbXhg==

currently-unhandled@^0.4.1:
version "0.4.1"
Expand Down Expand Up @@ -8717,6 +8717,11 @@ typedarray@^0.0.6, typedarray@~0.0.5:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^3.5.2:
version "3.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"
integrity sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==

uglify-es@^3.3.4:
version "3.3.9"
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677"
Expand Down