Skip to main content
Post Made Community Wiki
Source Link
T.J. Crowder
  • 1.1m
  • 201
  • 2k
  • 2k

addLead is a function that returns a function. Here's the same thing using function body syntax instead of concise body syntax, which may be clearer:

export const addLead = (lead) => { return (dispatch, getState) => { axios .post('/api/leads/', lead, tokenConfig(getState)) .then(........) }; } 

So you'd call addLead to get a function with lead bound to it:

const f = addLead("some lead"); 

...and then call that with dispatch and state as appropriate:

f("dispatch", "state"); 

Side note: It's a bit odd (without more context) that the function addLead returns doesn't return the result of calling axios. I would have expected it to be:

export const addLead = (lead) => (dispatch, getState) => axios .post('/api/leads/', lead, tokenConfig(getState)) .then(........); 

which is:

export const addLead = (lead) => { return (dispatch, getState) => { return axios .post('/api/leads/', lead, tokenConfig(getState)) .then(........); }; };