about summary refs log tree commit diff
path: root/src/state/models/feeds/posts-slice.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-08-05 11:29:55 -0700
committerGitHub <noreply@github.com>2023-08-05 11:29:55 -0700
commit89fc975a150d8c1f79d2a728f9f252fc3438a613 (patch)
tree251887b1eb13fbbeac74b0b4a43bbba2376fe0b2 /src/state/models/feeds/posts-slice.ts
parentd53cbb91bb91fe3da360c22b2dbd966b9bc39a83 (diff)
downloadvoidsky-89fc975a150d8c1f79d2a728f9f252fc3438a613.tar.zst
Perf: switch to stable react keys (#1113)
Diffstat (limited to 'src/state/models/feeds/posts-slice.ts')
-rw-r--r--src/state/models/feeds/posts-slice.ts18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/state/models/feeds/posts-slice.ts b/src/state/models/feeds/posts-slice.ts
index c02faed3b..d20c23b9c 100644
--- a/src/state/models/feeds/posts-slice.ts
+++ b/src/state/models/feeds/posts-slice.ts
@@ -3,8 +3,6 @@ import {RootStoreModel} from '../root-store'
 import {FeedViewPostsSlice} from 'lib/api/feed-manip'
 import {PostsFeedItemModel} from './post'
 
-let _idCounter = 0
-
 export class PostsFeedSliceModel {
   // ui state
   _reactKey: string = ''
@@ -12,15 +10,15 @@ export class PostsFeedSliceModel {
   // data
   items: PostsFeedItemModel[] = []
 
-  constructor(
-    public rootStore: RootStoreModel,
-    reactKey: string,
-    slice: FeedViewPostsSlice,
-  ) {
-    this._reactKey = reactKey
-    for (const item of slice.items) {
+  constructor(public rootStore: RootStoreModel, slice: FeedViewPostsSlice) {
+    this._reactKey = `slice-${slice.uri}`
+    for (let i = 0; i < slice.items.length; i++) {
       this.items.push(
-        new PostsFeedItemModel(rootStore, `slice-${_idCounter++}`, item),
+        new PostsFeedItemModel(
+          rootStore,
+          `${this._reactKey} - ${i}`,
+          slice.items[i],
+        ),
       )
     }
     makeAutoObservable(this, {rootStore: false})