1

If I attempt to set a previously defined memoized value to a list of values of length one, no error throws. If I set it to a list of length > 2 I get the following error

Error: You attempted to set the key `0` with the value `"acmemarkets"` on an object that is meant to be immutable and has been frozen.

SelectedStores is a value stored in a context - Relevant example code

  const logAnalyticsEvent = useCallback(
    (feelingHungryActionType: FeelingHungryActionType) => {
      logFeelingHungryAction({
        feelingHungryActionType,
        dietId: dietId ?? null,
        productUpcBeingViewed: currentProduct?.upc ?? null,
        selectedStores: selectedStores ?? [StoreNames.BrowseAllStores],
        greenOnly,
        feelingHungryAfterLikeAutoCloseDelayInMs,
        feelingHungryHowManyProductsToKeepInPreloadBuffer,
        feelingHungryHowManyProductsToLoadPerRequest,
      });
    },
    [
      dietId,
      currentProduct,
      selectedStores,
      greenOnly,
      feelingHungryAfterLikeAutoCloseDelayInMs,
      feelingHungryHowManyProductsToKeepInPreloadBuffer,
      feelingHungryHowManyProductsToLoadPerRequest,
      logFeelingHungryAction,
    ],
  );

If I change this to simply return a copy of selectedStores using

selectedStores.map(store=>store)
therealcobb
  • 147
  • 7
  • Does this answer your question? [You attempted to set the key on an object that is meant to be immutable and has been frozen](https://stackoverflow.com/questions/38270445/you-attempted-to-set-the-key-on-an-object-that-is-meant-to-be-immutable-and-has) – Youssouf Oumar Jun 07 '22 at 19:32
  • No, but thank you for the comment - I understand why you would not want to modify a prop that was passed into a function, but in this case, I'm setting the prop to a dictionary key of the same name which seems to be causing the issue. – therealcobb Jun 07 '22 at 19:33

0 Answers0