DINOD
Reactiflux2y ago
9 replies
DINO

Make Zustand store scalable

Hello,

This is my
Zustand
store state type:

type WaitlistState = {
  counterSaleWaitlist: CounterSaleWaitlistItemType[]
  salesInvoiceWaitlist: SalesInvoiceWaitlistItemType[]
  purchaseInvoiceWaitlist: PurchaseInvoiceWaitlistItemType[]
  addCounterSaleItem: (data: CounterSaleWaitlistItemType['data']) => void
  addSalesInvoiceItem: (data: SalesInvoiceWaitlistItemType['data']) => void
  addPurchaseInvoiceItem: (data: PurchaseInvoiceWaitlistItemType['data']) => void
  deleteItem: (date: string) => void
  deleteList: (
    list: 'counterSaleWaitlist' | 'salesInvoiceWaitlist' | 'purchaseInvoiceWaitlist'
  ) => void
  deleteAll: () => void
}


In the future I will add more invoices (up to 10), and I kind of don't like doing something like:

  counterSaleWaitlist: CounterSaleWaitlistItemType[]
  salesInvoiceWaitlist: SalesInvoiceWaitlistItemType[]
  purchaseInvoiceWaitlist: PurchaseInvoiceWaitlistItemType[]
  xInvoiceWaitlist: XInvoiceWaitlistItemType[]
  yInvoiceWaitlist: YInvoiceWaitlistItemType[]
  zInvoiceWaitlist: ZInvoiceWaitlistItemType[]
  addCounterSaleItem: (data: CounterSaleWaitlistItemType['data']) => void
  addSalesInvoiceItem: (data: SalesInvoiceWaitlistItemType['data']) => void
  addPurchaseInvoiceItem: (data: PurchaseInvoiceWaitlistItemType['data']) => void
  addPurchaseX: (data: XInvoiceWaitlistItemType['data']) => void
  addPurchaseY: (data: YInvoiceWaitlistItemType['data']) => void
  addPurchaseZ: (data: ZInvoiceWaitlistItemType['data']) => void
  // ...

Are there any common practices to handle such a thing?

Thanks.
Was this page helpful?