Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naming and add yalc #21

Merged
merged 4 commits into from
Jan 12, 2024
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"scripts": {
"ci": "yarn prettier && yarn compile && yarn lint && yarn test && yarn build",
"clean": "rimraf node_modules -g 'packages/*/.eslintcache' 'packages/*/*.tsbuildinfo' 'packages/*/dist' 'packages/*/.rollup.cache' 'packages/*/types'",
"clean": "rimraf node_modules -g 'packages/*/.eslintcache' 'packages/*/*.tsbuildinfo' 'packages/*/dist' 'packages/*/.rollup.cache' 'packages/*/types' 'packages/*/coverage'",
"compile": "yarn workspace @dolthub/react-hooks compile",
"build": "yarn workspace @dolthub/react-hooks build",
"lint": "yarn workspace @dolthub/react-hooks lint",
Expand Down
29 changes: 29 additions & 0 deletions packages/hooks/README.dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Developer notes

## Testing in a local app

Using [`yalc`](https://github.com/wclr/yalc) is the best way to test this library in another local package.

First, compile and build this package:

```zsh
% yarn dbuild
```

And publish to `yalc`:

```zsh
% yalc publish
```

The `yalc:publish` script will also achieve the above.

Then in your app, link to this package:

```zsh
other-app % yalc link @dolthub/react-hooks
```

And you will see and up-to-date version of this package. When you make a change to this package, you can push the change by running `yarn yalc:push`.

To remove the yalc package in your app, run `yalc remove --all`.
26 changes: 0 additions & 26 deletions packages/hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,3 @@ function MyComponent() {
return <div>Home</div>;
}
```

## Testing in a local package

First compile and build the package:

```
% yarn compile & yarn build
```

If you have a local copy of this package and want to test a change in another local
package, you can either add `@dolthub/react-hooks` and point it at the file path, or if
`@dolthub/react-hooks` is already installed add the file path to `resolutions` in your
`package.json`, like so:

```json
// ../other-package/package.json
{
...,
"resolutions": {
"@dolthub/react-hooks": "file:../../react-library/packages/hooks",
"@types/react": "18.2.33"
}
}
```

Note that you may also need the same `@types/react` version.
11 changes: 7 additions & 4 deletions packages/hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dolthub/react-hooks",
"author": "DoltHub",
"version": "0.1.4",
"version": "0.1.5",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/index.d.ts",
Expand All @@ -19,11 +19,13 @@
"scripts": {
"compile": "tsc -b",
"build": "rollup -c --bundleConfigAsCjs",
"build:watch": "rollup -c --bundleConfigAsCjs --watch",
"dbuild": "yarn compile && yarn build",
"lint": "eslint --cache --ext .ts,.js,.tsx,.jsx src",
"prettier": "prettier --check 'src/**/*.{js,ts}'",
"prettier-fix": "prettier --write 'src/**/*.{js,ts}'",
"test": "jest --env=jest-environment-jsdom"
"test": "jest --env=jest-environment-jsdom",
"yalc:publish": "yarn dbuild && yalc publish",
"yalc:push": "yarn dbuild && yalc push"
},
"peerDependencies": {
"react": "^18.2.0",
Expand Down Expand Up @@ -63,7 +65,8 @@
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-terser": "^7.0.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"yalc": "^1.0.0-pre.53"
},
"repository": {
"type": "git",
Expand Down
1 change: 0 additions & 1 deletion packages/hooks/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default [
{
input: "./types/index.d.ts",
output: [{ file: "dist/index.d.ts", format: "esm" }],
external: [/\.css$/],
plugins: [dts()],
},
];
2 changes: 1 addition & 1 deletion packages/hooks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export { default as useAnchorTag } from "./useAnchorTag";
export { default as useBaseUrl } from "./useBaseUrl";
export { default as useContextWithError } from "./useContextWithError";
export { default as useDelay } from "./useDelay";
export { createLink, default as useDownloadFile } from "./useDownloadFile";
export { default as useEffectAsync } from "./useEffectAsync";
export { default as useEffectOnMount } from "./useEffectOnMount";
export { default as useElementIsVisible } from "./useElementIsVisible";
export { default as useFocus } from "./useFocus";
export { default as useHostname } from "./useHostname";
export { GlobalHotKeys, useHotKeysForToggle } from "./useHotKeys";
export { default as useInterval } from "./useInterval";
export { default as useIsSignedIn } from "./useIsSignedIn";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { useEffect, useState } from "react";

// getHostFn is a function that returns the host to use based on location.hostname.
export default function useHostname(
getHostFn: () => string,
// getUrlFn is a function that returns the base url based on location.hostname.
export default function useBaseUrl(
getUrlFn: () => string,
defaultHost = "",
): string {
const [host, setHost] = useState(defaultHost);
const [setOnce, setSetOnce] = useState(false);

useEffect(() => {
if (typeof window !== "undefined" && !setOnce) {
setHost(getHostFn());
setHost(getUrlFn());
setSetOnce(true);
}
}, [host, setHost, getHostFn]);
}, [host, setHost, getUrlFn]);

return host;
}
2 changes: 1 addition & 1 deletion packages/hooks/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"include": ["./src"],
"exclude": ["./types", "./esm", "./cjs", "node_modules", "dist", "__tests__"],
"exclude": ["./types", "./esm", "./cjs", "node_modules", "./dist"],
"compilerOptions": {
"rootDir": "src",
"baseUrl": ".",
Expand Down
Loading
Loading