MCPcopy Create free account
hub / github.com/adobe/react-spectrum / move

Function move

packages/react-stately/src/data/useListData.ts:325–340  ·  view source on GitHub ↗
(key: Key, toIndex: number)

Source from the content-addressed store, hash-verified

323 });
324 },
325 move(key: Key, toIndex: number) {
326 dispatch(state => {
327 let index = state.items.findIndex(item => getKey!(item) === key);
328 if (index === -1) {
329 return state;
330 }
331
332 let copy = state.items.slice();
333 let [item] = copy.splice(index, 1);
334 copy.splice(toIndex, 0, item);
335 return {
336 ...state,
337 items: copy
338 };
339 });
340 },
341 moveBefore(key: Key, keys: Iterable<Key>) {
342 dispatch(state => {
343 let toIndex = state.items.findIndex(item => getKey!(item) === key);

Callers 2

moveBeforeFunction · 0.70
moveAfterFunction · 0.70

Calls 2

sliceMethod · 0.80
filterMethod · 0.65

Tested by

no test coverage detected