Effect CommunityEC
Effect Community•14mo ago•
10 replies
Aurélien (quasar.work)

Persisting Data Across Component Unmounts with `rx` and `rx-react`

This is probably a dumb question, but with rx & rx-react ; is there a way to persist the loaded data when the component unmounts, so that when the user gets back to the same component it does not need to re-request the data ?
Currently my data fetching is working fine, but it's re-fetching everytime I change my pages, so a bit meh.

I even tried with something like:
export const persistedCustomersRx = Rx.make<
  CustomerForAdminAllView["customers"]
>([]);

// ---

// tsx component
export const CustomersIndexTable = () => {
...
  const shop = useRxValue(shopRx);
  const [customers, customersGet] = useRx(customersRx);
  const [persistedCustomers, setPersistedCustomers] =
    useRx(persistedCustomersRx);

  useEffect(() => {
    if (persistedCustomers.length > 0) {
      return;
    }
    customersGet({ shopId: shop.value.id });
  }, []);
...
}


But even with that it seems to reset persistedCustomers back to [] on component refresh 🤔

Though I am neither sure about the syntax, nor the actual way of articulating what I want to achieve.
But I am pretty sure it's feasible without needing React Context, or am I wrong ?
Was this page helpful?