Skip to content

Instantly share code, notes, and snippets.

@ramakay
Created September 29, 2016 18:29
Show Gist options
  • Save ramakay/9f50ab96bb610623db96798531b1ef26 to your computer and use it in GitHub Desktop.
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.
/** 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