2

I am a newbie on react redux , can I create a Action with more than 2 field? normali an action return a object with

{type : same_vale, paylod : same_vale}

Is it possible to return from a action something like this:

{type : same_vale , paylod : same_vale, idx : same_vale}

Is this an error? it allowed only make something like that?:

{type : same_vale , paylod : { field1 : same_vale, idx : same_vale}

Thanks

iofjuupasli
  • 3,818
  • 1
  • 16
  • 17
Angelotti
  • 673
  • 1
  • 6
  • 20
  • The redux action should look like `{ type : , payload: , meta: }` and in the `meta` you could put whatever doesn't make sense as part of the payload – apokryfos Dec 19 '18 at 08:58
  • it's absolutely fine to add as many fields as you want, since action is a plain javascript object. For uniformity, it's advised to add "type" and "payload" as shown in 3rd option – Rikesh Subedi Dec 19 '18 at 08:58
  • For what you're asking, actually you can test it out easily and do a simple console log to see what are the object being passed over at reducer – Isaac Dec 19 '18 at 09:01

1 Answers1

3

You can do whatever you want with your actions, except it should have action.type property.

What is better in your question depends on case. I usually put all values in payload property: payload : { field1 : some_value, idx : some_id}

iofjuupasli
  • 3,818
  • 1
  • 16
  • 17