diff --git a/package.json b/package.json index 1b0a597..16e707a 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..4447382 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,3 @@ +import { UseDimensionsArgs, UseDimensionsHook } from "./types"; +declare function useDimensions({ liveMeasure }?: UseDimensionsArgs): UseDimensionsHook; +export default useDimensions; diff --git a/src/index.ts b/src/index.ts index 5fc60eb..e27b18a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,7 @@ function useDimensions({ liveMeasure = true }: UseDimensionsArgs = {}): UseDimensionsHook { const [dimensions, setDimensions] = useState({}); - const [node, setNode] = useState(null); + const [node, setNode] = useState(null); const ref = useCallback(node => { setNode(node); @@ -44,9 +44,10 @@ function useDimensions({ }; } } + return () => {} }, [node]); - return [ref, dimensions, node]; + return [ref, dimensions as DimensionObject, node]; } export default useDimensions; diff --git a/src/types.d.ts b/src/types.d.ts index abae2cf..00f160e 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -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 { diff --git a/tsconfig.json b/tsconfig.json index 257bd23..b978ad4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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 diff --git a/yarn.lock b/yarn.lock index 0a8e57f..020c8c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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"