Comments (4)
Wow ok, I was clearly quite wrong here lol. Thanks for the example! I don't think I understand why we don't want to use deps though. Any chance you could give me a TLDR?
Re: the docs, I do think they need something to explain how to use it like that, so ill have a crack at a PR when I get a moment
from use-debounce.
Ok cool! I was seeing this as a replacement for useCallback, but really it supplements it. So yeah, I will close the issue and have a crack at the docs later. Thanks for all the help!
from use-debounce.
Hi @JamesConsidine, Thank you for the issue!
We don't use deps array explicitly.
Some refs describing why it's better:
https://twitter.com/mostruash/status/1109134981182488576 + #21
With Example: #53
To use memorization you could combine useCallback + useDebouncedCallback:
// memoize
const fetchPage = useCallback(activePage => {
setContent({ title: activePage, body: "Lorem Ipsum" });
}, []);
// debounce
const [fetchPageDebounced] = useDebouncedCallback(fetchPage, 500);
In case you'd like to improve docs, I'll be glad to receive a PR :)
from use-debounce.
Any chance you could give me a TLDR?
The main reason is that automatic rules, like react-hooks/exhaustive-deps
, don't check whether deps are right for custom hooks. They check only for the original hooks. It's why the react team don't recommend to make your own deps array for custom hooks:
https://twitter.com/dan_abramov/status/1109136157403680768
from use-debounce.
Related Issues (20)
- "leading: true" not working for v7 HOT 8
- create-react-app 5 compatibility HOT 4
- useDebouncedCallback does not update state when react-dev-tools is open HOT 2
- errors in debounce fn are not propagated HOT 1
- useDebouncedCallback gives incorrect import suggestion in VSCode HOT 2
- Jest 28.0.0 and jest-environment-jsdom fails to import use-debounce in tests HOT 6
- Seems like useDebouncedCallback is executing async functions in render scope HOT 2
- use-debounce to auto-save multi input form HOT 1
- useDebouncedCallback should return the callback function HOT 3
- Cannot use import statement outside of a module - running with jest in ESM mode HOT 1
- Cannot find module 'use-debounce' HOT 6
- [9.0.1] TS7016: Could not find a declaration file for module 'use-debounce'. HOT 8
- Not react hook? HOT 1
- useDebouncedCallback - doesnt update when inner function updates HOT 2
- API of hooks are not documented HOT 2
- Incorrect return type for flush() function HOT 4
- useDebouncedCallback major change in v6.0.0. If you use older version you should go through Changelog to get a fresh API HOT 2
- isPending() state isn't reset to false if the tracked value hasn't changed. HOT 4
- Link to dan_abramov's tweet is a dead link now HOT 1
- Dependency Conflict with React 19.0.0-rc When Installing use-debounce HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from use-debounce.