stevenpersia/captain-hook
À propos
Des hooks React personnalisés pour votre projet.
Développement web et applicatifProgression mesurée des étoiles
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginalCaptain hook

Overview
Here is a modest list of hooks that I use every day. I will add more in the next few days, keep watching. And if you have some good hooks I would love to add them. So feel free to open a pull request.
Hooks
useFetch - View code
Useful hook if you want to fetch data.
How to use
Import hook :
import useFetch from "hooks/useFetch";
Then use like this :
const { response, errors } = useFetch("https://github.com/stevenpersia/");
Demo
useFullScreen - View code
Useful hook if you want to fullscreen an element of your page.
How to use
Import hook :
import useFullScreen from "hooks/useFullScreen";
Add :
const { elementFS, triggerFS, exitFS, isFS } = useFullScreen();
Then use like this :
<div ref={elementFS}>I want to fullscreen this div.</div>
<button onClick={triggerFS}>Trigger fullscreen</button>
<button onClick={exitFS}>Exit fullscreen</button>
Check if fullscreen is triggered :
console.log(isFS);
Demo
useHover - View code
Useful hook if you want to detect when the mouse is hovering an element.
How to use
Import hook :
import useHover from "hooks/useHover";
Add :
const [hoverRef, isHovered, event] = useHover();
Then use like this :
<div ref={hoverRef}>{isHovered ? "Hovered ! at " + [event.pageX, event.pageY].join(",") : "Hover me !"}</div>
Demo
useKeyPress - View code
Useful hook if you want to detect when user is pressing a specific key.
How to use
Import hook :
import useKeyPress from "hooks/useKeyPress";
Then use like this :
const hKeyPressed = useKeyPress("h");
console.log(hKeyPressed && "Hello !");
// → Hello !
Demo
useTitle - View code
Useful hook if you want to set a specific title to page.
How to use
Import hook :
import useTitle from "hooks/useTitle";
Then use like this :
useTitle("My title");
Demo
useToggle - View code
Useful hook if you want display/hide something with toggle.
How to use
Import hook :
import useToggle from "hooks/useToggle";
Then use like this :
const [open, toggle] = useToggle(false);
<Button onClick={toggle}>Show filters</Button>;
{
open && <Filters />;
}
Demo
useEventListener - View code
Useful hook if you want to create an event handler.
How to use
Import hook :
import useEventListener from "hooks/useEventListener";
Then use like this :
const [coords, setCoords] = useState({ x: 0, y: 0 });
useEventListener("mousemove", ({ clientX, clientY }) =>
setCoords({ x: clientX, y: clientY })
);
console.log(coords);
Demo
useInfiniteScroll - View code
Useful hook if you want to add the infinite scroll feature to your website.
How to use
Import hook :
import useInfiniteScroll from "hooks/useInfiniteScroll";
Then use like this :
const [isFetching, setIsFetching] = useInfiniteScroll(fetchData);
const fetchData = () => {
// ...
};
Demo
useFavicon - View code
Useful hook if you want to set a specific favicon to the page.
How to use
Import hook :
import useFavicon from "hooks/useFavicon";
Then use like this :
useFavicon("/path/image.png", "image/png");
Demo
useDebounce - View code
Useful hook if you want to set a debounced value.
How to use
Import hook :
import useDebounce from "hooks/useDebounce";
Then use like this :
const delay = 1000;
const debouncedValue = useDebounce(value, delay);
Demo
Star, Fork, Clone & Contribute
Feel free to contribute on this repository. If my work helps you, please give me back with a star. This means a lot to me and keeps me going!
Explorer des projets similaires
Chargement…