Comments (2)
what about a new useLazyFetch
hook?
import React from "react";
import { useFetch } from "usehooks-ts";
// until https://github.com/juliencrn/usehooks.ts/issues/37 is fixed
interface State<T> {
data?: T;
error?: Error;
}
interface Executer {
(): void;
}
interface LazyQuery<T> {
execute: Executer;
state: State<T> | undefined;
}
function useLazyFetch<T = unknown>(
url?: string,
options?: RequestInit,
): LazyQuery<T> {
const [state, setState] = React.useState<State<T> | undefined>(undefined);
return {
state,
execute: function (): void {
setState(useFetch(url, options));
},
};
}
export default useLazyFetch;
from usehooks-ts.
that break the rule of hooks :(
from usehooks-ts.
Related Issues (20)
- [BUG] LocalStorage is not immediately accessible. HOT 1
- hook "useUnmount" is in the documentation but not included in the package when installed via npm HOT 2
- [BUG] Can't resolve `lodash.debounce` HOT 1
- [BUG] useSessionStorage @2.11.0 HOT 2
- [BUG] Missing modules whie using with Next.js HOT 5
- [FEAT]: Implement optional peerDependencies HOT 3
- [BUG] upgrading from 2.10.0 breaks nextjs app HOT 1
- Error when running build [BUG] HOT 2
- Future of `.all-contributorsrc` HOT 1
- useIsClient mentions useSSR link which goes to 404 HOT 1
- [BUG]useOnClickOutside cant use the array of ref HOT 1
- [BUG] `useResizeObserver` mutate initialSize globally HOT 3
- [BUG] useScrollLock doesn't work in ios safari HOT 1
- useDarkMode resets HOT 5
- [BUG] useLocalStorage hook's option param is missing HOT 1
- [BUG] useScrollLock - Do not leave inline styles if they weren't present before the lock HOT 2
- [BUG] useWindowSize does not trigger on orientation change
- [BUG]
- Add support for "focusin" for `useOnClickOutside` hook HOT 1
- Examples first, then API docs HOT 2
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 usehooks-ts.