-
Notifications
You must be signed in to change notification settings - Fork 0
hooks / useDebounce #76
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
Open
VaseninaNastya
wants to merge
35
commits into
master
Choose a base branch
from
feature/useDebounce
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
44fe1f8
feat: add useDebounce
687b9c1
feat: add use-debounce-callback
865b3e8
feat: add useDebounse
51cf537
feat: resolve conflicts
256b0de
resolve conflicts
b04673f
fix: fix name
ecdb5be
fix: delete wrong changes
4565f11
fix: fix test
6f85519
fix: fix tests
0fe4443
chore: fix package.json
sadcitizen ef01236
refactor(usedebounce): рефакторинг хуков
458ed3e
Merge branch 'master' into feature/useDebounce
66f4185
feat(useDebounce): добавил tsconfig.build.json
a577238
feat(useDebounce): добавил tsconfig.build.json
610f581
test(hooks/usedebounce): тесты и ридми
c19db26
feat(hooks/usedebounce): рефактор и истории
02e2257
feat(hooks/useDebouncedValue): разобрался со storybook и mdx
4934f14
feat(hooks/useDebouncedCallback): истории
SmorodinVik 26c5f8d
feat(usedebounce): убрал story из документации
SmorodinVik 39661b7
Merge branch 'master' into feature/useDebounce
SmorodinVik e358b55
feat(usedebounce): обновил истории
SmorodinVik 157d3e4
feat(useDebounce): поправил стили
40feece
feat(useDebounce): поправил стили
6fce773
fix(useDebounce): фиксы после ревью
ef4b293
feat(useDebounce): css модули и обновления шаблонов
377bf15
feat(codeOfConduct): обновление имени файла стилей историй
6ddc8c2
Merge branch 'master' into feature/useDebounce
AMZhukov b7a1a1b
feat(useDebounce): add tests for useDebouncedCallback hook
AMZhukov f0665de
feat(useDebounce): refactor useDebouncedCallback to use useTimeout
AMZhukov afc67f2
feat(useDebounce): refactor` index.ts` to export directly
AMZhukov 1554c4f
fix(useDebounce): fix dependencies for `useDebounce`
AMZhukov 22daa71
refactor(useDebounce): fix markdown code `useDebounced`
AMZhukov 328d771
feat(useDebounce): improve type for `useDebouncedValue`
AMZhukov 757042a
fix(useDebounce): fix test for `useDebouncedCallback`
AMZhukov 51f20d4
feat(useArray): добавил css modules в истории
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| to: hooks/<%= h.changeCase.paramCase(name) %>/tsconfig.build.json | ||
| --- | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "exclude": ["src/*.tests.ts", "src/*.stories.tsx"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| flex-grow: 1; | ||
| } | ||
|
|
||
| button { | ||
| .button { | ||
| flex-basis: 100px; | ||
| flex-shrink: 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,5 +7,5 @@ | |
| "module": "commonjs", | ||
| "target": "es6" | ||
| }, | ||
| "include": ["src"] | ||
| "include": ["src", "../../types.d.ts"] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| src |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # `@byndyusoft-ui/use-debounced-callback` | ||
| --- | ||
|
|
||
| > A React hook that uses for delaying the execution of functions updates until a specified time period has passed without any further changes | ||
|
|
||
| ### Installation | ||
|
|
||
| ``` | ||
| npm i @byndyusoft-ui/use-debounced-callback | ||
| # or | ||
| yarn add @byndyusoft-ui/use-debounced-callback | ||
| ``` | ||
|
|
||
| ### Usage | ||
|
|
||
| ```ts | ||
| type THookReturn<T> = [T, (arg: T) => void]; | ||
|
|
||
| const useDebouncedValue = <T>(value: T, delay = 300): THookReturn<T> => { | ||
| const [debouncedValue, setValue] = useState(value); | ||
|
|
||
| const setDebouncedValue = useDebouncedCallback(setValue, delay); | ||
|
|
||
| return [debouncedValue, setDebouncedValue]; | ||
| }; | ||
| ``` | ||
|
|
||
| ### License | ||
|
|
||
| Apache-2.0 | ||
|
|
||
| ### Authors | ||
|
|
||
| Anastasia Vasenina, Viktor Smorodin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| { | ||
| "name": "@byndyusoft-ui/use-debounced-callback", | ||
| "version": "0.0.0", | ||
| "description": "Byndyusoft UI React Hook", | ||
| "keywords": [ | ||
| "byndyusoft", | ||
| "byndyusoft-ui", | ||
| "react", | ||
| "hook", | ||
| "debounce" | ||
| ], | ||
| "author": "Anastasia Vasenina <vasenina@byndyusoft.com>", | ||
| "homepage": "https://github.com/Byndyusoft/ui/tree/master/hooks/use-debounced-callback#readme", | ||
| "license": "Apache-2.0", | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/Byndyusoft/ui.git" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc --project tsconfig.build.json", | ||
| "clean": "rimraf dist", | ||
| "lint": "eslint src --config ../../eslint.config.js", | ||
| "test": "jest --config ../../jest.config.js --roots hooks/use-debounced-callback/src" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/Byndyusoft/ui/issues" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@byndyusoft-ui/use-timeout": "*" | ||
| }, | ||
| "peerDependencies": { | ||
| "@byndyusoft-ui/types": "*" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './useDebouncedCallback'; |
19 changes: 19 additions & 0 deletions
19
hooks/use-debounced-callback/src/useDebouncedCallback.docs.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { Markdown, Source, Canvas, Meta } from '@storybook/blocks'; | ||
| import * as useDebouncedCallbackStories from './useDebouncedCallback.stories'; | ||
| import Readme from '../README.md'; | ||
|
|
||
| <Meta title="hooks/useDebouncedCallback" of={useDebouncedCallbackStories} /> | ||
|
|
||
| <Markdown>{Readme}</Markdown> | ||
|
|
||
| ## Guide | ||
|
|
||
| To use the hook in your project you must: | ||
|
|
||
| 1. Import the hook where you need it: | ||
|
|
||
| <Source language="javascript" code="import useDebouncedCallback from '@byndyusoft-ui/use-debounced-callback';" /> | ||
|
|
||
| 2. Give callback and delay args. | ||
|
|
||
| <Canvas sourceState="shown" of={useDebouncedCallbackStories.DebouncedColorChangeStory} /> |
21 changes: 21 additions & 0 deletions
21
hooks/use-debounced-callback/src/useDebouncedCallback.stories.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| .container { | ||
| display: flex; | ||
| gap: 2rem; | ||
| } | ||
|
|
||
| .block { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 1rem; | ||
|
|
||
| width: 15rem; | ||
| } | ||
|
|
||
| .rectangle { | ||
| width: 100%; | ||
| height: 5rem; | ||
| } | ||
|
|
||
| .button { | ||
| height: 5rem; | ||
| } |
47 changes: 47 additions & 0 deletions
47
hooks/use-debounced-callback/src/useDebouncedCallback.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import React, { useState } from 'react'; | ||
| import type { StoryObj } from '@storybook/react'; | ||
| import useDebouncedCallback from './useDebouncedCallback'; | ||
| import styles from './useDebouncedCallback.stories.module.css'; | ||
|
|
||
| const COLORS = ['red', 'green', 'yellow']; | ||
|
|
||
| const DebouncedColorChange = () => { | ||
| const [firstColorIndex, setFirstColorIndex] = useState(0); | ||
| const [secondColorIndex, setSecondColorIndex] = useState(0); | ||
| const setDebouncedSecondColorIndex = useDebouncedCallback(setSecondColorIndex, 1000); | ||
|
|
||
| return ( | ||
| <div className={styles.container}> | ||
| <div className={styles.block}> | ||
| <button | ||
| className={styles.button} | ||
| type="button" | ||
| onClick={() => setFirstColorIndex((firstColorIndex + 1) % 3)} | ||
| > | ||
| Click for color change | ||
| </button> | ||
| <div className={styles.rectangle} style={{ backgroundColor: COLORS[firstColorIndex] }} /> | ||
| </div> | ||
|
|
||
| <div className={styles.block}> | ||
| <button | ||
| className={styles.button} | ||
| type="button" | ||
| onClick={() => setDebouncedSecondColorIndex((secondColorIndex + 1) % 3)} | ||
| > | ||
| Click for debounced color change (delay: 1000 ms) | ||
| </button> | ||
| <div className={styles.rectangle} style={{ backgroundColor: COLORS[secondColorIndex] }} /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export const DebouncedColorChangeStory: StoryObj<typeof DebouncedColorChange> = { | ||
| name: 'Debounced color change', | ||
| render: DebouncedColorChange | ||
| }; | ||
|
|
||
| export default { | ||
| title: 'hooks/useDebouncedCallback' | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.