flipper-plugin-redux-debugger icon indicating copy to clipboard operation
flipper-plugin-redux-debugger copied to clipboard

How do you pass a Payload when you dispatch an action?

Open Stophface opened this issue 3 years ago • 3 comments
trafficstars

From the code side I dispatch my action like this

    dispatch({
        type: DO_SOMETHING,
        payload: {
            foo: 'cat',
            bar: 'dog'
        }
    });

When I try to dispatch this action with a payload from the flipper plug in

{
    'foo': 'cat',
    'bar': 'dog'
}

It tells me undefined is not an object and pin points me to action.payload.foo. So I assume the payload is not passed from the plug in. How do I give it a payload?

Stophface avatar Feb 11 '22 20:02 Stophface

You need to pass the object you would dispatch in your code to the plugin. E.g. { type: DO_SOMETHING, payload: { foo: 'cat', bar: 'dog' } }

iAmHarmon avatar Feb 27 '22 19:02 iAmHarmon

In redux, even though payload is a standard but it is not a default field. The flexibility trade off requires user to supply the field name.

plwai avatar Mar 03 '22 13:03 plwai

If you have a payload which is not an object just pass {"payload": xxx}

uloco avatar Mar 17 '22 10:03 uloco