Skip to content

Commit

Permalink
Fix documentation for predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
littensy committed Apr 29, 2023
1 parent 648c21b commit dccc102
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/use-latest/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
## 🪝 `useLatest`

```ts
function useLatest<T>(value: T, shouldUpdate?: (previous?: T, current: T) => boolean): { current: T };
function useLatest<T>(value: T, isEqual?: (previous?: T, current: T) => boolean): { current: T };
```

Returns a ref object whose `current` property points to the latest version of the value.

It takes an optional inequality function to determine whether the value should be updated.
It takes an optional equality function to determine whether the values are equal. If false, the value will be updated.

### 📕 Parameters

- `value` - The value to wrap in a ref.
- `isEqual?` - An equality function. Defaults to a strict equality check (`===`).

### 📗 Returns

Expand Down
4 changes: 2 additions & 2 deletions src/use-latest/use-latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Predicate, isStrictEqual } from "../use-previous";
* Returns a mutable ref that points to the latest value of the input.
*
* Takes an optional `predicate` function as the second argument that receives
* the previous and current value. If the predicate returns `true`, the newest
* value will be returned on the next render.
* the previous and current value. If the predicate returns `false`, the values
* are not equal, and the previous value is updated.
*
* @param value The value to track.
* @returns A mutable reference to the value.
Expand Down
6 changes: 3 additions & 3 deletions src/use-previous/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
## 🪝 `usePrevious`

```tsx
function usePrevious<T>(value: T, shouldUpdate?: (previous?: T, current: T) => boolean): T | undefined;
function usePrevious<T>(value: T, isEqual?: (previous?: T, current: T) => boolean): T | undefined;
```

Returns a reference to the value from the previous render, or `undefined` on the first render.

It takes an optional inequality function to determine whether the value should be updated.
It takes an optional equality function to determine whether the values are equal. If false, the value will be updated.

### 📕 Parameters

- `value` - The value to track.
- `shouldUpdate?` - A function that determines whether the value should be updated. Defaults to an inequality check.
- `isEqual?` - An equality function. Defaults to a strict equality check (`===`).

### 📗 Returns

Expand Down
4 changes: 2 additions & 2 deletions src/use-previous/use-previous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const isStrictEqual = (a: unknown, b: unknown) => a === b;
* on the first render.
*
* Takes an optional `predicate` function as the second argument that receives
* the previous and current value. If the predicate returns `true`, the newest
* value will be returned on the next render.
* the previous and current value. If the predicate returns `false`, the values
* are not equal, and the previous value is updated.
*
* @param value The value to return on the next render if it changes.
* @param predicate Optional function to determine whether the value changed.
Expand Down

0 comments on commit dccc102

Please sign in to comment.