jk-gan / flipper-plugin-redux-debugger

Flipper plugin for Redux in React Native
MIT License
117 stars 20 forks source link

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

Open Stophface opened 2 years ago

Stophface commented 2 years ago

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?

iAmHarmon commented 2 years ago

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' } }

plwai commented 2 years ago

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.

uloco commented 2 years ago

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