-
Notifications
You must be signed in to change notification settings - Fork 94
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
Add new prop to be able to skip the initial fetch on component mount #70
base: next
Are you sure you want to change the base?
Add new prop to be able to skip the initial fetch on component mount #70
Conversation
Codecov Report
@@ Coverage Diff @@
## master #70 +/- ##
==========================================
+ Coverage 98.83% 98.85% +0.01%
==========================================
Files 10 10
Lines 689 697 +8
Branches 161 168 +7
==========================================
+ Hits 681 689 +8
Misses 6 6
Partials 2 2
Continue to review full report at Codecov.
|
@ghengeveld Have the deploy jobs been working before or have they just been failing? |
This is interesting. Can't you use |
You can ignore those, the deploys are in It only really deploys from |
@ghengeveld from what I have seen so far it appears |
any progress on it? |
The work being done in https://github.com/async-library/future/tree/core will address the use case of debounced actions. However this is not going to be released any time soon. As for this PR, I haven't heard back from @markusylisiurunen regarding the reason to use |
@ghengeveld Yeah, you are right. The behaviour can be implemented by using the |
Let's say we have search, and user should enter at least 3 characters. const doSearch = async (query) => { ... }
const [search, setSearch] = useState('')
// trigger with useEffect
const { run, cancel, ... } = useAsync({
deferFn: doSearch,
})
useEffect(() => {
if (search.length > 2) {
run(search)
} else {
cancel()
}
}, [search])
// triggered with skip change
const { ... } = useAsync({
promiseFn: doSearch,
skip: search.length < 3
}) And you prefer to trigger it using via |
@sbogdaniuk That was basically the reason I was thinking about adding a flag for skipping with the |
@sbogdaniuk You could probably use const doSearch = async (query) => { ... }
const [search, setSearch] = useState('')
const watchFn = ({ search }, prev) => search.length > 2 && search !== prev.search
const { ... } = useAsync({ deferFn: doSearch, watchFn, search }) Edit: oh wait that's only for promiseFn, obviously, so it would still start a request on first render. So yeah, |
Description
Added a new prop for
Async
anduseAsync
to be able to skip the initial render when component mounts. This can be useful, for example, for debounced actions.Breaking changes
Should not have any breaking changes.
Checklist
<Async>
anduseAsync()