Skip to content

Commit

Permalink
run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Aug 18, 2024
1 parent add85c7 commit faaba1f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions docs/utilities/split.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ The `splitAtom` utility supports a second argument which is a key extractor func
```ts
export function splitAtom<Item, Key>(
arrAtom: WritableAtom<Item[], [Item[]], void> | Atom<Item[]>,
keyExtractor?: (item: Item) => Key
keyExtractor?: (item: Item) => Key,
)
```

Important considerations for the `keyExtractor`:

- If `splitAtom` is used within a React render loop, the `keyExtractor` must be a stable function that maintains object equality (shallow equality). This requirement doesn't apply outside of render loops.
- Providing a `keyExtractor` enhances the stability of the atom output (which makes memoization hit cache more often). It prevents unnecessary subatom recreation due to index shifts in the source array.
- Providing a `keyExtractor` enhances the stability of the atom output (which makes memoization hit cache more often). It prevents unnecessary subatom recreation due to index shifts in the source array.
- `keyExtractor` is an optional optimization that should only be used if the extracted key is guaranteed unique for each item in the array.


### Example Usage

Here's an example demonstrating the use of `splitAtom`:
Expand Down

0 comments on commit faaba1f

Please sign in to comment.