redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Is it safe to use action.meta.arg.originalArgs for passing custom options to a rejected action listener?

Open AndreasNH opened this issue 1 year ago • 1 comments

I'm working on a listener that handles rejected actions, specifically focusing on conditionally logging 412 errors based on certain conditions. Here's a simplified version of my listener:

// Pseudo listener  
export const create412ErrorListener = () => ({
  predicate: (action: PayloadAction) => isRejected(action) && is412Error(action),
  effect: (action: PayloadAction) => {
    if (action?.meta?.arg?.originalArgs?.opts?.log412) {
      Logger.warn(action.payload)
    }
  },
});

In this case, I'm checking action.meta.arg.originalArgs.opts.log412 to decide whether to log 412 errors.

Additionally, in one of my components, I pass this option like so:

// Some component
const { data } = useQuery({
  criteria, 
  opts: { log412: true },
});

My Question: Is it safe to rely on action.meta.arg.originalArgs for passing custom options like this? Specifically, is originalArgs meant for public use, or is it primarily intended for internal purposes?

AndreasNH avatar Oct 10 '24 11:10 AndreasNH

I would consider it an implementation detail, but I think the chances of us changing it in practice are low.

EskiMojo14 avatar Oct 10 '24 14:10 EskiMojo14