An open API service indexing awesome lists of open source software.

https://github.com/emapco/react-util-hooks

A collection of hooks I've created across various projects.
https://github.com/emapco/react-util-hooks

Last synced: 3 months ago
JSON representation

A collection of hooks I've created across various projects.

Awesome Lists containing this project

README

        

# react-util-hooks
A collection of hooks I've created across various projects.

## useWindowSize usage
```tsx
import { useMemo } from "react";
import { useScreenSize } from "path/to/hook/useScreenSize";

function App() {
// object destruct the window size boolean states you are interested in
const { isSmall, isLarge } = useWindowSize();

// utilize the booleans as needed
const iconSize = useMemo(() => {
if (isLarge) return 30;
if (isSmall) return 24;
else return 22;
}, [isSmall, isLarge]);
}
```

## useAutoFocus usage
Useful when you want to auto focus an element when it enters the viewport.
For example, to auto focus a search field when a dropdown is toggled open.

```tsx
import { useMemo } from "react";
import { useAutoFocus } from "path/to/hook/useAutoFocus";

function App() {
// object destruct the window size boolean states you are interested in
const { ref, inViewport } = useAutoFocus();

// pass ref to component/element that needs auto focus when visible
return ()
}
```