-
What's the best way to add a object to an array in store? setStore('array', [...store.array, newEl])
setStore('array', store.array.length, newEl)
setStore(produce(store => store.array.push(newEl))) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
At the end of the list technically 2, 3, 1 in that order for performance. But I wouldn't sweat it. In most other situations 1 over 3. Generally speaking I'd say number 1 is idiomatic but hey if there are places to optimize like 2 go for it. 3 makes certain logic easier to write. |
Beta Was this translation helpful? Give feedback.
-
Guys check out setCourseStore("sections", selfSecIdx, "chapters", (chap) =>
chap?.toSpliced(
selfVidIdx + (isEdgeAtBottom ? 1 : 0),
0,
incomingChp[srcVidIdx],
),
);
setCourseStore("sections", srcSecIdx, "chapters", (chap) =>
chap?.toSpliced(srcVidIdx, 1),
); |
Beta Was this translation helpful? Give feedback.
At the end of the list technically 2, 3, 1 in that order for performance. But I wouldn't sweat it. In most other situations 1 over 3. Generally speaking
produce
has a tax per index that changes so cloning the array is just easy/better.I'd say number 1 is idiomatic but hey if there are places to optimize like 2 go for it. 3 makes certain logic easier to write.