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

How to access results from REST service?

Open tomsoderlund opened this issue 7 years ago • 4 comments

Can I somehow immediately access the results from the REST service?

E.g. the example:

dispatch(rest.actions.entry({id: 1}));

If my REST server returns the ID of the new entry, how can I use that in my frontend app?

tomsoderlund avatar Jan 10 '19 14:01 tomsoderlund

Hi @temnoregg dispatch(rest.actions.entry({id: 1})).then((data) => ...)

lexich avatar Jan 10 '19 19:01 lexich

Thank you @lexich! So simple...

tomsoderlund avatar Jan 10 '19 21:01 tomsoderlund

A follow-up question, @lexich:

  1. I've figured that the transformer function should always return the complete (sub-)state, right?
  2. It's also the results from this transformer function that I receive in .then((data) => ...) above, right?

I have a problem right now in a "delete" action; my REST service returns the ID of a deleted item, my front-end wants to have this ID, but since the transformer function needs the complete item list, this ID is lost.

tomsoderlund avatar Jan 10 '19 22:01 tomsoderlund

@tomsoderlund I don't understand problem, may be you need to save this ID in another place. Can you show your case in details

lexich avatar Jan 15 '19 09:01 lexich