reakit
Version:
Toolkit for building accessible rich web apps with React
17 lines (14 loc) • 377 B
text/typescript
import { Item } from "./types";
const nullItem = { id: null, ref: { current: null } };
export function placeItemsAfter(
items: Item[],
id: string,
shouldInsertNullItem?: boolean
) {
const index = items.findIndex((item) => item.id === id);
return [
...items.slice(index + 1),
...(shouldInsertNullItem ? [nullItem] : []),
...items.slice(0, index),
];
}