Redux

Rewinder

Member
Joined
May 22, 2016
Messages
12
In this thread I will ask stupid questions about Redux.


Question 1

I'm trying to call an API from a form using redux-form. Do I dispatch an action inside the "handleSubmit" function, and then another one when the call returns?

Does that make any sense? I can't find an example online that uses an API call.


Edit: Or maybe the first action calls the second action when the api call returns?
 

_kabal_

Executive Member
Joined
Oct 24, 2005
Messages
5,922
No, you could do it inside your reducer function, without middleware, but then it becomes impure.

If you are fine with that, then go ahead.

You are still going to need something to do an Ajax request though. You could use vanilla XMLHttpRequest, or if you don't need to support old browsers, you can use the fetch API - https://developer.mozilla.org/en/docs/Web/API/Fetch_API

Else you could at a pinch use jquery ajax, and get its Promise functionality while you are at it
 
Last edited:

Rewinder

Member
Joined
May 22, 2016
Messages
12
I think for now I will just call the api in the click function with axios, then dispatch an action when it returns.
 
Top