Skip to content

Commit c45ffbb

Browse files
committed
refactor: depreciate usePrevious for withPrevious
1 parent 89d6595 commit c45ffbb

File tree

5 files changed

+3627
-3747
lines changed

5 files changed

+3627
-3747
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ Visit the [REPL demo](https://svelte.dev/repl/1d3e752c51b848e6af264f3244f3e85c?v
2727

2828
## Usage
2929

30-
`usePrevious` accepts an initial value, and returns a tuple comprising a [Writable](https://svelte.dev/tutorial/writable-stores) and a [Readable](https://svelte.dev/tutorial/readable-stores) store.
30+
`withPrevious` accepts an initial value, and returns a tuple comprising a [Writable](https://svelte.dev/tutorial/writable-stores) and a [Readable](https://svelte.dev/tutorial/readable-stores) store.
3131

3232
```svelte
3333
<script>
34-
import { usePrevious } from 'svelte-previous';
34+
import { withPrevious } from 'svelte-previous';
3535
3636
export let name;
3737
// current is writable, while previous is read-only.
38-
const [currentName, previousName] = usePrevious(0);
38+
const [currentName, previousName] = withPrevious(0);
3939
// To update the values, assign to the writable store.
4040
$: $currentName = name;
4141
</script>
@@ -45,17 +45,17 @@ transition from {$previousName} to {$currentName}.
4545

4646
## Options
4747

48-
`usePrevious` takes an options object as its second argument.
48+
`withPrevious` takes an options object as its second argument.
4949

5050
### `numToTrack: number`
5151

52-
By default, `usePrevious` tracks one previous value.
52+
By default, `withPrevious` tracks one previous value.
5353

5454
To track more than one value, set `numToTrack`.
5555

5656
```svelte
5757
<script>
58-
const [current, prev1, prev2] = usePrevious(0, { numToTrack: 2 });
58+
const [current, prev1, prev2] = withPrevious(0, { numToTrack: 2 });
5959
</script>
6060
6161
from {$prev2} to {$prev1} to {$current}.
@@ -69,7 +69,7 @@ Set `requireChange = false` to change this behaviour.
6969

7070
```svelte
7171
<script>
72-
const [current, previous] = usePrevious(0, { requireChange: false });
72+
const [current, previous] = withPrevious(0, { requireChange: false });
7373
</script>
7474
```
7575

@@ -81,7 +81,7 @@ Provide a custom `isEqual` function to compare objects.
8181

8282
```svelte
8383
<script>
84-
const [current, previous] = usePrevious(0, {
84+
const [current, previous] = withPrevious(0, {
8585
isEqual: (a, b) => a.name === b.name && a.age === b.age,
8686
});
8787
</script>
@@ -93,7 +93,7 @@ It is also possible to use [lodash.isequal](https://www.npmjs.com/package/lodash
9393
<script>
9494
import isEqual from 'lodash.isequal';
9595
96-
const [current, previous] = usePrevious(0, {
96+
const [current, previous] = withPrevious(0, {
9797
isEqual: isEqual,
9898
});
9999
</script>

0 commit comments

Comments
 (0)