Skip to content

Commit 52ccf4a

Browse files
committed
doc(README) Rewording and reformatting
1 parent 05e88b0 commit 52ccf4a

1 file changed

Lines changed: 40 additions & 34 deletions

File tree

README.md

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,40 @@
33

44
# React Utils
55

6-
This package contains common hooks and components to use in a React application.
6+
- [About](#about)
7+
- [Installation](#installation)
8+
- [API](#API)
9+
- [Hooks](#Hooks)
10+
- [`useAnimate`](#useAnimate)
11+
- [`useAnimateCustom`](#useAnimateCustom)
12+
- [`useIntersectionObserver`](#useIntersectionObserver)
13+
- [`useInterval`](#useInterval)
14+
- [`useGatherMemo`](#useGatherMemo)
15+
- [`useLazyStateUpdate`](#useLazyStateUpdate)
16+
- [`useMediaQuery`](#useMediaQuery)
17+
- [`useScrollIntoView`](#useScrollIntoView)
18+
- [`useSVGMousePosition`](#useSVGMousePosition)
19+
- [`useTimeout`](#useTimeout)
20+
- [`useTransition`](#useTransition)
21+
- [`useValidation`](#useValidation)
22+
- [Components](#Components)
23+
- [`<Filter>`](#Filter)
24+
25+
## About
726

8-
**Hooks**
27+
This package contains common hooks and components to use in a React application.
928

10-
- [`useAnimate`](#useAnimate)
11-
- [`useAnimateCustom`](#useAnimateCustom)
12-
- [`useIntersectionObserver`](#useIntersectionObserver)
13-
- [`useInterval`](#useInterval)
14-
- [`useGatherMemo`](#useGatherMemo)
15-
- [`useLazyStateUpdate`](#useLazyStateUpdate)
16-
- [`useMediaQuery`](#useMediaQuery)
17-
- [`useScrollIntoView`](#useScrollIntoView)
18-
- [`useSVGMousePosition`](#useSVGMousePosition)
19-
- [`useTimeout`](#useTimeout)
20-
- [`useTransition`](#useTransition)
21-
- [`useValidation`](#useValidation)
29+
## Installation
2230

23-
**Components**
31+
`npm i @cdoublev/react-utils`
2432

25-
- [`<Filter>`](#Filter)
33+
`@cdoublev/react-utils` is built with the current NodeJS version as target, meaning that it should probably be transpiled in order to be used in your application using its own targets.
2634

27-
***
35+
## API
2836

29-
**(Hooks)**
37+
### Hooks
3038

31-
## useAnimate
39+
#### useAnimate
3240

3341
`useAnimate` abstracts using `Element.animate()` from the Web Animation API ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API)).
3442

@@ -42,7 +50,7 @@ This package contains common hooks and components to use in a React application.
4250

4351
**Example:** [CodePen](https://codepen.io/creative-wave/pen/JjjZRyE)
4452

45-
## useAnimateCustom
53+
#### useAnimateCustom
4654

4755
`useAnimateCustom` abstracts using `animate()`, a lightweight alternative to [`Element.animate()`](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API) or its [official polyfill](https://github.com/web-animations/web-animations-js), with some [extra features](https://github.com/creativewave/animate#extra-features).
4856

@@ -63,7 +71,7 @@ Related:
6371
- [(React) Framer Motion](https://www.framer.com/api/motion/)
6472
- [Tween.js](https://github.com/tweenjs/tween.js)
6573

66-
## useIntersectionObserver
74+
#### useIntersectionObserver
6775

6876
`useIntersectionObserver` abstracts using an `IntersectionObserver` to execute a function when an `Element` intersects an ancestor, ie. when it enters in or exits from its viewport.
6977

@@ -86,7 +94,7 @@ Each observed `Element` will be unobserved before unmount, and the current `Inte
8694

8795
**Note:** make sure to use a memoized value for `threshold` if it's an `Array`, as well as for `onEnter` and `onExit`.
8896

89-
## useInterval
97+
#### useInterval
9098

9199
*Credit: [Dan Abramov](https://overreacted.io/making-setinterval-declarative-with-react-hooks/).*
92100

@@ -99,7 +107,7 @@ It will stop executing `Function` if:
99107
- the reference to `Function` has changed
100108
- the delay (`Number`) has changed
101109

102-
## useGatherMemo
110+
#### useGatherMemo
103111

104112
`useGatherMemo` abstracts gathering (merging) and/or picking (destructuring) properties from object(s) while memoizing the result to avoid unneeded updates in the component and its children.
105113

@@ -139,7 +147,7 @@ const allOptions = { ...subOptions, display: 'fullscreen' }
139147

140148
**Warning:** don't over use it, ie. use it only with large objects, otherwise it will negatively impact performances by increasing the call stack as well as the amount of data stored in memory.
141149

142-
## useLazyStateUpdate
150+
#### useLazyStateUpdate
143151

144152
`useLazyStateUpdate` abstracts delaying a state update.
145153

@@ -149,13 +157,13 @@ It could be used eg. to delay the render of an error notice after validating an
149157

150158
`useLazyStateUpdate :: [a, Number] -> a`
151159

152-
## useMediaQuery
160+
#### useMediaQuery
153161

154162
`useMediaQuery` abstracts using `windows.matchMedia()` to observe a match against a query, eg. `(min-width: 50em)`.
155163

156164
`useMediaQuery :: String -> Boolean`
157165

158-
## useScrollIntoView
166+
#### useScrollIntoView
159167

160168
`useScrollIntoView` abstracts using `Element.scrollIntoView()` when a `scroll` event is emitted.
161169

@@ -187,7 +195,7 @@ Both should be used. To set `document` as `root`, the corresponding callback ref
187195
- `onEnter` and `onExit` are optional callbacks defined in [`useIntersectionObserver`](#useIntersectionObserver)
188196
- `touchSensitivity` (default to `150`) is a distance in pixels that the finger or stylus should move to be handled as a scroll event
189197

190-
## useSVGMousePosition
198+
#### useSVGMousePosition
191199

192200
`useSVGMousePosition` abstracts translating the position of the mouse relative to an `<svg>` in `document`, into a position relative to its `viewBox`.
193201

@@ -210,7 +218,7 @@ The first [`CallbackRef`](https://reactjs.org/docs/refs-and-the-dom.html#callbac
210218
- `isFixed` (default to `false`) is an optional `Boolean` to flag the `target` as having a fixed position in the viewport of `document`, ie. in `window`
211219
- `precision` (default to `2`) is an optional number to round `Position` values
212220

213-
## useTimeout
221+
#### useTimeout
214222

215223
`useTimeout` abstracts using `setTimeout()` and `clearTimeout()` to schedule the execution of a `Function`, without worrying about cancelling the timer to avoid a memory leak such as *a React state update on an unmounted component*.
216224

@@ -221,7 +229,7 @@ It will stop executing `Function` if:
221229
- the reference to `Function` has changed
222230
- the delay (`Number`) has changed
223231

224-
## useTransition
232+
#### useTransition
225233

226234
`useTransition` abstracts scheduling multiple state updates over time using different delays and durations.
227235

@@ -241,19 +249,17 @@ Related packages:
241249
- [React Transition Group](https://github.com/reactjs/react-transition-group)
242250
- [React Spring (useTransition)](https://www.react-spring.io/docs/hooks/use-transition)
243251

244-
## useValidation
252+
#### useValidation
245253

246254
`useValidation` abstracts using the Constraint Validation API ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Constraint_validation)) to validate a form field on blur (default) or on change.
247255

248256
`useValidation :: { onChange?: Function, onBlur?: Function, validateOnChange?: Boolean } -> [String, Props]`
249257

250258
It returns any error message from the Constraint Validation API, and a collection of component properties such as `onChange` and `onBlur` event handlers, to assign to an `<input>`, `<select>` or `<textarea>`. Each of those handlers will be composed with a corresponding handler given as argument.
251259

252-
***
253-
254-
**(Components)**
260+
### Components
255261

256-
## Filter
262+
#### Filter
257263

258264
`<Filter>` provides common filter effects to use in a `SVGElement`.
259265

0 commit comments

Comments
 (0)