Skip to content

Commit a1f4a40

Browse files
committed
.
1 parent 3e5f4de commit a1f4a40

File tree

12 files changed

+69
-13
lines changed

12 files changed

+69
-13
lines changed

esm/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare type Fn<ARGS extends any[], R> = (...args: ARGS) => R;
2+
declare const useEventCallback: <A extends any[], R>(fn: Fn<A, R>) => Fn<A, R>;
3+
export default useEventCallback;

esm/index.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare type Fn<ARGS extends any[], R> = (...args: ARGS) => R;
2+
declare const useEventCallback: <A extends any[], R>(fn: Fn<A, R>) => Fn<A, R>;
3+
export default useEventCallback;

lib/index.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
"repository": "ssh://[email protected]/WillBooster/react-use-event-callback.git",
66
"license": "Apache-2.0",
77
"author": "WillBooster Inc.",
8-
"main": "dist/index.js",
9-
"typings": "dist/index.d.ts",
8+
"main": "lib/index.js",
9+
"module": "esm/index.js",
10+
"types": "lib/index.d.js",
11+
"files": [
12+
"lib",
13+
"esm"
14+
],
1015
"scripts": {
11-
"build": "tsc",
16+
"build": "yarn build:cjs && yarn build:esm",
17+
"build:cjs": "tsc --build tsconfig.cjs.json",
18+
"build:esm": "tsc --build tsconfig.esm.json",
1219
"cleanup": "yarn format && yarn lint-fix",
1320
"format": "sort-package-json && yarn prettier",
1421
"lint": "eslint \"./{packages/*/,}{src,__tests__}/**/*.{js,jsx,ts,tsx}\"",
@@ -17,8 +24,11 @@
1724
"typecheck": "tsc --noEmit"
1825
},
1926
"prettier": "@willbooster/prettier-config",
27+
"peerDependencies": {
28+
"react": ">=16.8"
29+
},
2030
"devDependencies": {
21-
"@types/react": "16.9.34",
31+
"@types/react": "^16.8.8",
2232
"@typescript-eslint/eslint-plugin": "2.26.0",
2333
"@typescript-eslint/parser": "2.26.0",
2434
"@willbooster/eslint-config-ts": "3.0.0",
@@ -31,7 +41,7 @@
3141
"husky": "4.2.3",
3242
"lint-staged": "10.1.1",
3343
"prettier": "2.0.2",
34-
"react": "16.13.1",
44+
"react": "^16.8.4",
3545
"sort-package-json": "1.40.0",
3646
"typescript": "3.8.3"
3747
}

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { useCallback, useLayoutEffect, useRef } from 'react';
1+
import { useLayoutEffect, useCallback, useRef } from 'react';
22

33
type Fn<ARGS extends any[], R> = (...args: ARGS) => R;
44

5-
export function useEventCallback<A extends any[], R>(fn: Fn<A, R>): Fn<A, R> {
6-
const ref = useRef<Fn<A, R>>(fn);
5+
const useEventCallback = <A extends any[], R>(fn: Fn<A, R>): Fn<A, R> => {
6+
let ref = useRef<Fn<A, R>>(fn);
77
useLayoutEffect(() => {
88
ref.current = fn;
99
});
1010
return useCallback((...args) => ref.current(...args), []);
11-
}
11+
};
12+
13+
export default useEventCallback;

tsconfig.json renamed to tsconfig.base.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "esnext",
54
"moduleResolution": "node",
65
"alwaysStrict": true,
76
"strict": true,
@@ -11,7 +10,6 @@
1110
"resolveJsonModule": true,
1211
"sourceMap": true,
1312
"importHelpers": false,
14-
"outDir": "dist",
1513
"typeRoots": ["./node_modules/@types", "./@types"],
1614
"declaration": true
1715
},

tsconfig.cjs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.base",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "./lib",
6+
},
7+
"include": ["src/**/*", "__tests__/**/*", "packages/*/src/**/*", "packages/*/__tests__/**/*"]
8+
}

tsconfig.esm.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.base",
3+
"compilerOptions": {
4+
"module": "esnext",
5+
"outDir": "./esm",
6+
},
7+
"include": ["src/**/*", "__tests__/**/*", "packages/*/src/**/*", "packages/*/__tests__/**/*"]
8+
}

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
108108
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
109109

110-
"@types/react@16.9.34":
110+
"@types/react@^16.8.8":
111111
version "16.9.34"
112112
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.34.tgz#f7d5e331c468f53affed17a8a4d488cd44ea9349"
113113
integrity sha512-8AJlYMOfPe1KGLKyHpflCg5z46n0b5DbRfqDksxBLBTUpB75ypDBAO9eCUcjNwE6LCUslwTz00yyG/X9gaVtow==
@@ -1739,7 +1739,7 @@ react-is@^16.8.1:
17391739
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
17401740
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
17411741

1742-
react@16.13.1:
1742+
react@^16.8.4:
17431743
version "16.13.1"
17441744
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
17451745
integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==

0 commit comments

Comments
 (0)