Search code examples
typescriptreact-nativereduxredux-sagaredux-toolkit

Non-serializable value was detected in action


I'm trying to make Error param in payload, but redux-toolkit showing error "Non serializable value...".How I can pass Error type in props?

p.s. I don't want to disable serializableCheck or another options


Solution

  • The answer from Mark Erikson here answers why you shouldn't have non-serializable data in payloads or in your store.

    The solution is to simply follow the recommended advice and use serializable values. You can pass the details required to construct the error as serializable data. E.g. you can store & pass data like:

    {
      hasError: true,
      errorName: 'ValidationError',
      errorMessage: 'Foo must be greater than Bar'
    }
    

    You can safely pass this information in payloads, & select the data from your store to do whatever you like with, including throwing an actual Error object if you desire.