Created
September 29, 2016 18:29
-
-
Save ramakay/9f50ab96bb610623db96798531b1ef26 to your computer and use it in GitHub Desktop.
An Example of how to Seed a Redux store and then push a route.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Usecase: Fetch a NLC ( Natural Language Classification ) Respopnse | |
Assumes: ReactGo Boilerplate. | |
inclusion of IBM Cognitive API | |
Axios promise library | |
React-Middleware-Thunk | |
----- | |
Focus on: Pushing a Store dispatch and then creating a route. | |
**/ | |
export function fetchProductsNLC (data) { | |
const topClass = data.top_class | |
return dispatch => { | |
return makeContentRequest('post', '', {text: topClass}, '/productData') | |
.then( | |
(response) => { | |
return dispatch(initEntrySuccess(response.data, topClass, data)) | |
} | |
) | |
.then( | |
(response) => { | |
// NLC Response Receive and `initEntrySuccess` has seeded the store, now lets relocate! | |
dispatch(push('/Products')) | |
} | |
) | |
.catch((e) => dispatch(initEntryFailure({ errobj: e,error: "Oops! Something went wrong and we couldn't create Search"}))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment