Skip to content

Commit e60d767

Browse files
committed
Initial commit
0 parents  commit e60d767

19 files changed

+4327
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.js linguist-detectable=false

.github/CODEOWNERS

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This is a comment.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in
5+
# the repo. Unless a later match takes precedence, they will
6+
# be requested for review when someone opens a pull request.
7+
* @prc5
8+
9+
# Order is important; the last matching pattern takes the most
10+
# precedence. When someone opens a pull request that only
11+
# modifies JS files, only @js-owner and not the global
12+
# owner(s) will be requested for a review.
13+
# *.js @js-owner
14+
15+
# You can also use email addresses if you prefer. They'll be
16+
# used to look up users just like we do for commit author
17+
# emails.
18+
19+
20+
# In this example, @doctocat owns any files in the build/logs
21+
# directory at the root of the repository and any of its
22+
# subdirectories.
23+
# /build/logs/ @doctocat
24+
25+
# The `docs/*` pattern will match files like
26+
# `docs/getting-started.md` but not further nested files like
27+
# `docs/build-app/troubleshooting.md`.
28+
29+
30+
# In this example, @octocat owns any file in an apps directory
31+
# anywhere in your repository.
32+
# apps/ @octocat
33+
34+
# In this example, @doctocat owns any file in the `/docs`
35+
# directory in the root of your repository.
36+
# /docs/ @doctocat

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
/dist
14+
15+
# misc
16+
.eslintcache
17+
.idea
18+
.vscode
19+
.DS_Store
20+
.env.local
21+
.env.development.local
22+
.env.test.local
23+
.env.production.local
24+
25+
npm-debug.log*
26+
yarn-debug.log*
27+
yarn-error.log*

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src
2+
node_modules

.prettierrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"printWidth": 100,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": false,
7+
"trailingComma": "all",
8+
"bracketSpacing": true,
9+
"jsxBracketSameLine": false,
10+
"proseWrap": "always",
11+
"arrowParens": "always"
12+
}

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# CHANGELOG
2+
3+
## Version: 0.1.0
4+
5+
##### Published: 17.10.2021
6+
7+
- Added: useDidMount hook
8+
- Added: useDidRender hook
9+
- Added: useDidUpdate hook
10+
- Added: useWillUnmount hook

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 BetterTyped
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# React Performance Hooks
2+
3+
[![NPM](https://img.shields.io/npm/v/@better-typed/react-performance-hooks.svg)](https://www.npmjs.com/package/@better-typed/react-performance-hooks)
4+
![npm bundle size](https://img.shields.io/bundlephobia/minzip/@better-typed/react-performance-hooks)
5+
![npm type definitions](https://img.shields.io/npm/types/@better-typed/react-performance-hooks)
6+
![NPM](https://img.shields.io/npm/l/@better-typed/react-performance-hooks)
7+
![npm](https://img.shields.io/npm/dm/@better-typed/react-performance-hooks)
8+
![GitHub stars](https://img.shields.io/github/stars/BetterTyped/react-performance-hooks?style=social)
9+
10+
> Debounce and throttle your functions to gain performance boost!
11+
12+
- [Better Typed](https://github.com/BetterTyped)
13+
14+
## Features
15+
16+
- :rocket: Simple, fast and light
17+
- :factory: Debounce and Throttle
18+
- 🪗 Lifecycle events handling
19+
20+
## Install
21+
22+
```bash
23+
npm install --save @better-typed/react-performance-hooks
24+
```
25+
26+
or
27+
28+
```bash
29+
yarn add @better-typed/react-performance-hooks
30+
```
31+
32+
## useDebounce
33+
34+
This hook allows debouncing of the given function.
35+
36+
```tsx
37+
import React from "react";
38+
import { useDebounce } from "@better-typed/react-performance-hooks";
39+
40+
const MyComponent: React.FC = ({ delay }) => {
41+
const {debounce, reset, active} = useDebounce(delay)
42+
43+
// Standard usage
44+
const onTyping = () => {
45+
debounce(() => {
46+
// debounced logic
47+
})
48+
}
49+
50+
// Dynamic delay value
51+
const onTypingDynamic = (value: string, customDelay: number) => {
52+
debounce(() => {
53+
// debounced logic
54+
}, customDelay)
55+
}
56+
57+
return (
58+
// ...
59+
)
60+
}
61+
62+
```
63+
64+
## useThrottle
65+
66+
This hook allows debouncing of the given function.
67+
68+
```tsx
69+
import React from "react";
70+
import { useThrottle } from "@better-typed/react-performance-hooks";
71+
72+
const MyComponent: React.FC = ({ delay }) => {
73+
const {throttle, reset, active} = useThrottle(delay)
74+
75+
// Standard usage
76+
const onScroll = () => {
77+
throttle(() => {
78+
// throttle logic
79+
})
80+
}
81+
82+
// Dynamic delay value
83+
const onScrollDynamic = (value: string, customDelay: number) => {
84+
throttle(() => {
85+
// throttle logic
86+
}, customDelay)
87+
}
88+
89+
return (
90+
// ...
91+
)
92+
}
93+
94+
```

package.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"name": "@better-typed/react-window-hooks",
3+
"version": "0.8.0",
4+
"author": "prc5",
5+
"license": "MIT",
6+
"description": "React window hooks",
7+
"repository": "BetterTyped/react-window-hooks",
8+
"main": "dist/index.cjs.js",
9+
"module": "dist/index.esm.js",
10+
"types": "dist/index.d.ts",
11+
"source": "src/index.ts",
12+
"jsnext:main": "dist/index.esm.js",
13+
"engines": {
14+
"node": ">=8",
15+
"npm": ">=5"
16+
},
17+
"private": false,
18+
"peerDependencies": {
19+
"react": ">= 16.8.0"
20+
},
21+
"scripts": {
22+
"build": "rollup -c",
23+
"prepare": "install-peers && yarn build",
24+
"test": "react-scripts test"
25+
},
26+
"eslintConfig": {
27+
"extends": [
28+
"react-app",
29+
"react-app/jest"
30+
]
31+
},
32+
"browserslist": {
33+
"production": [
34+
">0.2%",
35+
"not dead",
36+
"not op_mini all"
37+
],
38+
"development": [
39+
"last 1 chrome version",
40+
"last 1 firefox version",
41+
"last 1 safari version"
42+
]
43+
},
44+
"devDependencies": {
45+
"@rollup/plugin-babel": "^5.3.0",
46+
"@rollup/plugin-commonjs": "^21.0.0",
47+
"@rollup/plugin-node-resolve": "^13.0.5",
48+
"@svgr/rollup": "^5.5.0",
49+
"@testing-library/jest-dom": "^5.11.4",
50+
"@testing-library/react": "^11.1.0",
51+
"@testing-library/user-event": "^12.1.10",
52+
"@types/jest": "^26.0.15",
53+
"@types/lodash": "^4.14.182",
54+
"@types/node": "^12.0.0",
55+
"@types/react": "^17.0.0",
56+
"@types/react-dom": "^17.0.0",
57+
"@zerollup/ts-transform-paths": "^1.7.18",
58+
"gh-pages": "^3.2.3",
59+
"install-peers-cli": "^2.2.0",
60+
"postcss": "^8.3.9",
61+
"reflect-metadata": "^0.1.13",
62+
"rollup": "^2.58.0",
63+
"rollup-plugin-copy": "^3.4.0",
64+
"rollup-plugin-delete": "^2.0.0",
65+
"rollup-plugin-dts": "^4.0.0",
66+
"rollup-plugin-peer-deps-external": "^2.2.4",
67+
"rollup-plugin-postcss": "^4.0.1",
68+
"rollup-plugin-terser": "^7.0.2",
69+
"rollup-plugin-typescript2": "^0.30.0",
70+
"rollup-plugin-url": "^3.0.1",
71+
"typescript": "^4.1.2"
72+
},
73+
"files": [
74+
"dist"
75+
],
76+
"keywords": [
77+
"react",
78+
"hooks",
79+
"lifecycle",
80+
"use",
81+
"did",
82+
"mount",
83+
"update",
84+
"unmount",
85+
"render",
86+
"hook",
87+
"useDidMount",
88+
"useDidUnmount",
89+
"useDidRender",
90+
"useWillUnmount"
91+
],
92+
"dependencies": {
93+
"@better-typed/react-lifecycle-hooks": "^1.0.5"
94+
}
95+
}

rollup.config.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import path from "path";
2+
import { DEFAULT_EXTENSIONS } from "@babel/core";
3+
4+
import pkg from "./package.json";
5+
import resolve from "@rollup/plugin-node-resolve";
6+
import babel from "@rollup/plugin-babel";
7+
import external from "rollup-plugin-peer-deps-external";
8+
import del from "rollup-plugin-delete";
9+
import typescript from "rollup-plugin-typescript2";
10+
import commonjs from "@rollup/plugin-commonjs";
11+
import svgr from "@svgr/rollup";
12+
import url from "rollup-plugin-url";
13+
import postcss from "rollup-plugin-postcss";
14+
import dts from "rollup-plugin-dts";
15+
import copy from "rollup-plugin-copy";
16+
import { terser } from "rollup-plugin-terser";
17+
18+
export default [
19+
{
20+
input: pkg.source,
21+
output: [
22+
{ file: pkg.main, format: "cjs", exports: "named", sourcemap: true },
23+
{ file: pkg.module, format: "esm", exports: "named", sourcemap: true },
24+
],
25+
plugins: [
26+
del({ targets: ["dist/*"] }),
27+
external({
28+
includeDependencies: true,
29+
}),
30+
resolve({
31+
browser: true,
32+
moduleDirectories: ["node_modules", "src"],
33+
}),
34+
commonjs({
35+
include: ["node_modules/**"],
36+
}),
37+
typescript({
38+
declaration: true,
39+
rollupCommonJSResolveHack: true,
40+
}),
41+
babel({
42+
exclude: ["node_modules/**"],
43+
extensions: [...DEFAULT_EXTENSIONS, ".ts", ".tsx"],
44+
}),
45+
postcss({
46+
minimize: true,
47+
extract: "assets/styles/index.css",
48+
modules: {
49+
globalModulePaths: [/^((?!module.css)[\s\S])*$/],
50+
},
51+
}),
52+
url({
53+
fileName: "[dirname][hash][extname]",
54+
sourceDir: path.join(__dirname, "src"),
55+
}),
56+
svgr({
57+
svgoConfig: {
58+
plugins: {
59+
removeViewBox: false,
60+
},
61+
},
62+
}),
63+
copy({
64+
targets: [{ src: "src/assets/styles/light-theme.css", dest: "dist/assets/styles" }],
65+
}),
66+
terser({
67+
compress: true,
68+
}),
69+
],
70+
external: Object.keys(pkg.peerDependencies || {}),
71+
},
72+
{
73+
input: pkg.source,
74+
output: [{ file: pkg.types, format: "es" }],
75+
external: [/\.scss$/, /\.css$/],
76+
plugins: [
77+
dts({
78+
compilerOptions: {
79+
baseUrl: "./src",
80+
},
81+
}),
82+
],
83+
},
84+
];

src/hooks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./use-debounce";
2+
export * from "./use-throttle";

0 commit comments

Comments
 (0)