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

Make repeated calls to the same endpoint/method

Open jakeaaron opened this issue 9 years ago • 3 comments

Hello,

I know I've commented on another issue before, but could you show how one could make concurrent calls to the same method? You mentioned using request, but how does one update state with request responses?

Thanks very much for your time

jakeaaron avatar Jul 17 '17 20:07 jakeaaron

Hi, you should use your own reducer

Promise.all([
rest.data.request(1),
rest.data.request(2)
]).then(data => dispatch(sendCompositeData( data )))

lexich avatar Jul 18 '17 08:07 lexich

Hi @lexich , I have some doubts with this.

I have a component A that render two times a component B. In the component B, in its componentDidMount method, I make a POST request by redux-api. The problem is that both components get the same response, that one that resolves first.
Am I doing anything wrong? How can I fix it?

Here is my call in component B:

this.props.dispatch(api.actions.signature.post({}, { body: JSON.stringify(this.param) }, (err, data) => { this.setState({ signatureData: data }) }));

ghost avatar May 24 '18 02:05 ghost

Hi @agustin-vieta There are different ways to solve your problem. First of all this lib is named "redux-api" and the best way to keep data is not to use component state and replace it with redux store.
Request e.g. you can call in component A, and components B will only get data from store.

lexich avatar May 24 '18 06:05 lexich