Skip to content

♻️ refactor(HostedCart): resolve order ID once using resolvedOrderId #739

@acasazza

Description

@acasazza

Problem

In HostedCart.tsx, the pattern order?.id ?? orderId (where orderId comes from localStorage.getItem(persistKey)) was repeated multiple times across the useEffect, leading to duplication and reduced readability:

  • order?.id == null && orderId == null
  • order?.id != null || orderId != null
  • orderId: order?.id ?? orderId
  • orderId: order?.id ?? orderId ?? ""

Solution

Introduce a single resolvedOrderId variable at the top of the useEffect that merges both sources:

const resolvedOrderId = order?.id ?? localStorage.getItem(persistKey)

All subsequent null checks and usages then reference resolvedOrderId consistently, simplifying the conditions and removing the ?? "" fallback.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingrefactor

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions