Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/atomic-state/react-kuh

TypeScript-ready React (kinda) useful stuff
https://github.com/atomic-state/react-kuh

custom-hooks react react18

Last synced: 3 months ago
JSON representation

TypeScript-ready React (kinda) useful stuff

Awesome Lists containing this project

README

        

### react-kuh

TypeScript-ready React (kinda) useful hooks

#### `useWindowSize()`

Usage

```tsx
import { useWindowSize } from 'react-kuh'

function App(){
const windowSize = useWindowSize()

return (


Width: {windowSize.width}


Height: {windowSize.height}



)
}
```

#### `useBoolean()`

Usage

```tsx
import { useBoolean } from 'react-kuh'

function App(){
const [active, actions] = useBoolean(false) // if not present, default is null

return (


Active
Inactive
Inactive
actions.set(false)}>Set
Reset

)
}
```

#### `useObject`

Usage

```tsx
import { useObject } from 'react-kuh'

type NoteType = {
title: string
content: string
}

function App() {
// Type is not required if it should be inferred from the default value
const [note, actions] = useObject({
title: '',
content: ''
})

function randomizeNote() {
actions.setValue({
title: Math.random().toString(12).split('.')[1],
content: Math.random().toString(12).split('.')[1]
})
}

return (


{
actions.setPartialValue({
title: e.target.value
})
}}
/>
{
actions.setPartialValue({
content: e.target.value
})
}}
/>
Reset to initial value
Random

)
}
```

#### `useSecondRender`

Returns `true` after the first render

#### `BrowserOnly` (component)

This component renders its children after the first render. This can be used as a boundary when using SSR and a component should only be rendered in the client.

Usage

```jsx
import { BrowserOnly } from 'react-kuh'

export default function Page(){
return (


This is SSR



This is not SSR




)
}
```