diff --git a/.gitignore b/.gitignore index c9075ddf..712d064b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ node_modules # build -lib/ +types/ cjs/ dist/ esm/ diff --git a/package.json b/package.json index c491ada1..2869d358 100644 --- a/package.json +++ b/package.json @@ -12,15 +12,11 @@ "lint": "yarn workspace @dolthub/react-hooks lint", "prettier": "yarn workspace @dolthub/react-hooks prettier" }, - "dependencies": { - "react": "^18.2.0" - }, "devDependencies": { "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-typescript": "^11.1.5", "@types/eslint": "^8", - "@types/react": "^18.2.40", "@types/rollup-plugin-peer-deps-external": "^2", "@typescript-eslint/eslint-plugin": "^6.13.2", "@typescript-eslint/parser": "^6.13.2", diff --git a/packages/hooks/package.json b/packages/hooks/package.json index 2730c05c..8bc1b558 100644 --- a/packages/hooks/package.json +++ b/packages/hooks/package.json @@ -12,13 +12,14 @@ "scripts": { "compile": "tsc -b", "build": "rollup -c --bundleConfigAsCjs", + "build:watch": "rollup -c --bundleConfigAsCjs --watch", "lint": "eslint --cache --ext .ts,.js,.tsx,.jsx src", "prettier": "prettier --check 'src/**/*.{js,ts}'", "prettier-fix": "prettier --write 'src/**/*.{js,ts}'" }, "peerDependencies": { - "react": "*", - "react-dom": "*" + "@types/react": ">=18.2", + "react": ">=18.2" }, "devDependencies": { "@babel/preset-react": "^7.23.3", @@ -28,15 +29,11 @@ "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-typescript": "^11.1.5", "@types/eslint": "^8", - "@types/react": "^18.2.40", - "@types/react-dom": "^18", "@types/rollup-plugin-peer-deps-external": "^2", "@typescript-eslint/eslint-plugin": "^6.13.2", "@typescript-eslint/parser": "^6.13.2", "eslint": "^8.55.0", "prettier": "^3.1.0", - "react": "^18.2.0", - "react-dom": "^18.2.0", "rollup": "^4.6.1", "rollup-plugin-dts": "^6.1.0", "rollup-plugin-peer-deps-external": "^2.2.4", diff --git a/packages/hooks/rollup.config.js b/packages/hooks/rollup.config.js index 57d5c9b6..1369b7c3 100644 --- a/packages/hooks/rollup.config.js +++ b/packages/hooks/rollup.config.js @@ -11,13 +11,12 @@ const packageJson = require("./package.json"); export default [ { input: "src/index.ts", - external: ["react", "react-dom"], + external: ["react"], output: [ { file: packageJson.main, format: "cjs", sourcemap: true, - name: "react-ts-lib", }, { file: packageJson.module, @@ -40,7 +39,7 @@ export default [ ], }, { - input: "dist/esm/types/index.d.ts", + input: "types/index.d.ts", output: [{ file: "dist/index.d.ts", format: "esm" }], external: [/\.css$/], plugins: [dts()], diff --git a/packages/hooks/src/useReactiveSize.ts b/packages/hooks/src/useReactiveSize.ts index 591dca1a..7a6fb601 100644 --- a/packages/hooks/src/useReactiveSize.ts +++ b/packages/hooks/src/useReactiveSize.ts @@ -4,9 +4,7 @@ import useEffectOnMount from "./useEffectOnMount"; export function useReactiveHeight( elem?: E | null, ): E["clientHeight"] { - const [clientHeight, setClientHeight] = useState( - elem?.clientHeight ?? window.innerHeight, - ); + const [clientHeight, setClientHeight] = useState(elem?.clientHeight ?? 0); useEffectOnMount(() => { const handleResize = () => @@ -30,11 +28,10 @@ export function useReactiveWidth( elem?: E | null, mobileBreakpoint = 768, ): { clientWidth: E["clientWidth"]; isMobile: boolean } { - const [clientWidth, setClientWidth] = useState( - elem?.clientWidth ?? window.innerWidth, - ); + const [clientWidth, setClientWidth] = useState(elem?.clientWidth ?? 0); useEffectOnMount(() => { + setClientWidth(elem?.clientWidth ?? window.innerWidth); const handleResize = () => setClientWidth(elem?.clientWidth ?? window.innerWidth); window.addEventListener("resize", handleResize); diff --git a/packages/hooks/tsconfig.json b/packages/hooks/tsconfig.json index 7b4893d9..4ac5f616 100644 --- a/packages/hooks/tsconfig.json +++ b/packages/hooks/tsconfig.json @@ -1,6 +1,6 @@ { "include": ["./src"], - "exclude": ["./lib", "./esm", "./cjs"], + "exclude": ["./types", "./esm", "./cjs"], "compilerOptions": { "rootDir": "src", "baseUrl": ".", diff --git a/yarn.lock b/yarn.lock index 1b36a652..7ab7554b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1484,15 +1484,11 @@ __metadata: "@rollup/plugin-node-resolve": "npm:^15.2.3" "@rollup/plugin-typescript": "npm:^11.1.5" "@types/eslint": "npm:^8" - "@types/react": "npm:^18.2.40" - "@types/react-dom": "npm:^18" "@types/rollup-plugin-peer-deps-external": "npm:^2" "@typescript-eslint/eslint-plugin": "npm:^6.13.2" "@typescript-eslint/parser": "npm:^6.13.2" eslint: "npm:^8.55.0" prettier: "npm:^3.1.0" - react: "npm:^18.2.0" - react-dom: "npm:^18.2.0" rollup: "npm:^4.6.1" rollup-plugin-dts: "npm:^6.1.0" rollup-plugin-peer-deps-external: "npm:^2.2.4" @@ -1501,8 +1497,8 @@ __metadata: tslib: "npm:^2.6.2" typescript: "npm:^5.3.2" peerDependencies: - react: "*" - react-dom: "*" + "@types/react": ">=18.2" + react: ">=18.2" languageName: unknown linkType: soft @@ -2299,44 +2295,6 @@ __metadata: languageName: node linkType: hard -"@types/prop-types@npm:*": - version: 15.7.11 - resolution: "@types/prop-types@npm:15.7.11" - checksum: e53423cf9d510515ef8b47ff42f4f1b65a7b7b37c8704e2dbfcb9a60defe0c0e1f3cb1acfdeb466bad44ca938d7c79bffdd51b48ffb659df2432169d0b27a132 - languageName: node - linkType: hard - -"@types/react-dom@npm:^18": - version: 18.2.17 - resolution: "@types/react-dom@npm:18.2.17" - dependencies: - "@types/react": "npm:*" - checksum: 33b53078ed7e9e0cfc4dc691e938f7db1cc06353bc345947b41b581c3efe2b980c9e4eb6460dbf5ddc521dd91959194c970221a2bd4bfad9d23ebce338e12938 - languageName: node - linkType: hard - -"@types/react@npm:*": - version: 18.2.42 - resolution: "@types/react@npm:18.2.42" - dependencies: - "@types/prop-types": "npm:*" - "@types/scheduler": "npm:*" - csstype: "npm:^3.0.2" - checksum: 2946d78c1f9a220a4dfedd7995b8bcba47235b19756bf3dd845c604bb24fff8d0ff5be81c0c98ac7f4488791e8c7e6cbcc4898c40c0209d74a1223b8fbfb994f - languageName: node - linkType: hard - -"@types/react@npm:^18.2.40": - version: 18.2.41 - resolution: "@types/react@npm:18.2.41" - dependencies: - "@types/prop-types": "npm:*" - "@types/scheduler": "npm:*" - csstype: "npm:^3.0.2" - checksum: 5cc72491ce8be95e7bbedd8bf039ca971772ecd22d989feb045af7e73247c7e6cff25a2f1c2200be461fb2f6b5aacef739e1ba9fd83c744209dfd3ce8aa75afe - languageName: node - linkType: hard - "@types/resolve@npm:1.20.2": version: 1.20.2 resolution: "@types/resolve@npm:1.20.2" @@ -2354,13 +2312,6 @@ __metadata: languageName: node linkType: hard -"@types/scheduler@npm:*": - version: 0.16.8 - resolution: "@types/scheduler@npm:0.16.8" - checksum: f86de504945b8fc41b1f391f847444d542e2e4067cf7e5d9bfeb5d2d2393d3203b1161bc0ef3b1e104d828dabfb60baf06e8d2c27e27ff7e8258e6e618d8c4ec - languageName: node - linkType: hard - "@types/semver@npm:^7.5.0": version: 7.5.6 resolution: "@types/semver@npm:7.5.6" @@ -3381,13 +3332,6 @@ __metadata: languageName: node linkType: hard -"csstype@npm:^3.0.2": - version: 3.1.2 - resolution: "csstype@npm:3.1.2" - checksum: 32c038af259897c807ac738d9eab16b3d86747c72b09d5c740978e06f067f9b7b1737e1b75e407c7ab1fe1543dc95f20e202b4786aeb1b8d3bdf5d5ce655e6c6 - languageName: node - linkType: hard - "debug@npm:4, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.2, debug@npm:^4.3.4": version: 4.3.4 resolution: "debug@npm:4.3.4" @@ -5840,7 +5784,7 @@ __metadata: languageName: node linkType: hard -"loose-envify@npm:^1.1.0, loose-envify@npm:^1.4.0": +"loose-envify@npm:^1.4.0": version: 1.4.0 resolution: "loose-envify@npm:1.4.0" dependencies: @@ -7050,18 +6994,6 @@ __metadata: languageName: node linkType: hard -"react-dom@npm:^18.2.0": - version: 18.2.0 - resolution: "react-dom@npm:18.2.0" - dependencies: - loose-envify: "npm:^1.1.0" - scheduler: "npm:^0.23.0" - peerDependencies: - react: ^18.2.0 - checksum: 66dfc5f93e13d0674e78ef41f92ed21dfb80f9c4ac4ac25a4b51046d41d4d2186abc915b897f69d3d0ebbffe6184e7c5876f2af26bfa956f179225d921be713a - languageName: node - linkType: hard - "react-is@npm:^16.13.1": version: 16.13.1 resolution: "react-is@npm:16.13.1" @@ -7084,7 +7016,6 @@ __metadata: "@rollup/plugin-node-resolve": "npm:^15.2.3" "@rollup/plugin-typescript": "npm:^11.1.5" "@types/eslint": "npm:^8" - "@types/react": "npm:^18.2.40" "@types/rollup-plugin-peer-deps-external": "npm:^2" "@typescript-eslint/eslint-plugin": "npm:^6.13.2" "@typescript-eslint/parser": "npm:^6.13.2" @@ -7097,7 +7028,6 @@ __metadata: eslint-plugin-react: "npm:^7.33.2" eslint-plugin-react-hooks: "npm:^4.6.0" prettier: "npm:^3.1.0" - react: "npm:^18.2.0" rollup: "npm:^4.6.1" rollup-plugin-peer-deps-external: "npm:^2.2.4" rollup-plugin-postcss: "npm:^4.0.2" @@ -7106,15 +7036,6 @@ __metadata: languageName: unknown linkType: soft -"react@npm:^18.2.0": - version: 18.2.0 - resolution: "react@npm:18.2.0" - dependencies: - loose-envify: "npm:^1.1.0" - checksum: b562d9b569b0cb315e44b48099f7712283d93df36b19a39a67c254c6686479d3980b7f013dc931f4a5a3ae7645eae6386b4aa5eea933baa54ecd0f9acb0902b8 - languageName: node - linkType: hard - "reflect.getprototypeof@npm:^1.0.4": version: 1.0.4 resolution: "reflect.getprototypeof@npm:1.0.4" @@ -7506,15 +7427,6 @@ __metadata: languageName: node linkType: hard -"scheduler@npm:^0.23.0": - version: 0.23.0 - resolution: "scheduler@npm:0.23.0" - dependencies: - loose-envify: "npm:^1.1.0" - checksum: b777f7ca0115e6d93e126ac490dbd82642d14983b3079f58f35519d992fa46260be7d6e6cede433a92db70306310c6f5f06e144f0e40c484199e09c1f7be53dd - languageName: node - linkType: hard - "semver@npm:^6.3.0, semver@npm:^6.3.1": version: 6.3.1 resolution: "semver@npm:6.3.1"