lexich/redux-api

Make repeated calls to the same endpoint/method

jakeaaron opened this issue · 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

Hi, you should use your own reducer

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

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 }) }));

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.