0.8.3 • Published 4 years ago

@walltowall/hooks v0.8.3

Weekly downloads
6
License
UNLICENSED
Repository
-
Last release
4 years ago

@walltowall/hooks

Collection of reusable react hooks for Wall-to-Wall Gatsby websites.

Features

  • Re-usable stateful logic for functional React components.

Install

npm install --save @walltowall/hooks

How to use

// To import a hook,
import { hookName } from '@walltowall/hooks'

API

All functions and constants are exported from the root @walltowall/hooks package.

Hooks

useLocation

Returns the current window location from @reach/router.

Example
const location = useLocation()
// => 'careers'

useScrollDirection

(threshold: Number) => Object

Returns the current scroll direction with a customizeable threshold. A threshold is the minimum number of pixels that must be travelled before the scroll direction is considered to have changed.

Example
const scrollDirection = useScrollDirection(200)
// => { direction: 1, isScrollingDown: true, isScrollingUp: false }

useDynamicScript

(id: String, src: String, callback: Function) => Boolean

Allows for loading of external scripts at runtime. Returns a boolean indicating if the script has been loaded. The loaded script will be appended to the end of <body> with the provided id.

Can provide an optional callback that will get assigned to the <script> tag's onload attribute and called once the script is loaded.

Example
const isLoaded = useDynamicScript('stripe', 'https://js.stripe.com/v3/')
// => true

useURLSearchParam

<T extends String | number>(key: String, defaultValue: T) => T

Allows for syncing a component's local state value with a URL query parameter. Anytime the stateful value is updated, the URL parameter will be updated.

Unlike the useState hook, stateful values with useUrlSearchParam must be serializeable in a URL, so only strings or numbers are valid inputs.

Example
const [query, setQuery] = useURLSearchParam('hello', 'world')
// => http://localhost:3000/?hello=world
0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago